Skip to content

Commit e970afb

Browse files
committed
Upgrade from Laravel 10 to 11
1 parent 4f73033 commit e970afb

File tree

8 files changed

+5084
-3951
lines changed

8 files changed

+5084
-3951
lines changed

app/Http/Controllers/UserController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public function syncPermissions($request, $user)
110110
{
111111
$roles = $request->get('roles', []);
112112
$permissions = $request->get('permissions', []);
113+
//convert collection values to integers
114+
115+
$permissions = ($permissions) ? array_map('intval', $permissions) : [];
113116
$roles = Role::query()->find($roles);
114117

115118
$user->syncPermissions($permissions);

app/Http/Middleware/TeamsPermission.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ class TeamsPermission
1616
*/
1717
public function handle(Request $request, Closure $next): Response
1818
{
19+
1920
if(auth()->user() !== null){
2021
// session value set on login
22+
2123
setPermissionsTeamId(session('team_id'));
2224
}
25+
2326
// other custom ways to get team_id
2427
/*if(!empty(auth('api')->user())){
2528
// `getTeamIdFromToken()` example of custom method for getting the set team_id

bootstrap/app.php

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,50 @@
11
<?php
22

3-
/*
4-
|--------------------------------------------------------------------------
5-
| Create The Application
6-
|--------------------------------------------------------------------------
7-
|
8-
| The first thing we will do is create a new Laravel application instance
9-
| which serves as the "glue" for all the components of Laravel, and is
10-
| the IoC container for the system binding all of the various parts.
11-
|
12-
*/
13-
14-
$app = new Illuminate\Foundation\Application(
15-
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
16-
);
17-
18-
/*
19-
|--------------------------------------------------------------------------
20-
| Bind Important Interfaces
21-
|--------------------------------------------------------------------------
22-
|
23-
| Next, we need to bind some important interfaces into the container so
24-
| we will be able to resolve them when needed. The kernels serve the
25-
| incoming requests to this application from both the web and CLI.
26-
|
27-
*/
28-
29-
$app->singleton(
30-
Illuminate\Contracts\Http\Kernel::class,
31-
App\Http\Kernel::class
32-
);
33-
34-
$app->singleton(
35-
Illuminate\Contracts\Console\Kernel::class,
36-
App\Console\Kernel::class
37-
);
38-
39-
$app->singleton(
40-
Illuminate\Contracts\Debug\ExceptionHandler::class,
41-
App\Exceptions\Handler::class
42-
);
43-
44-
/*
45-
|--------------------------------------------------------------------------
46-
| Return The Application
47-
|--------------------------------------------------------------------------
48-
|
49-
| This script returns the application instance. The instance is given to
50-
| the calling script so we can separate the building of the instances
51-
| from the actual running of the application and sending responses.
52-
|
53-
*/
54-
55-
return $app;
3+
use App\Http\Middleware\TeamsPermission;
4+
use Illuminate\Foundation\Application;
5+
use Illuminate\Foundation\Configuration\Exceptions;
6+
use Illuminate\Foundation\Configuration\Middleware;
7+
8+
return Application::configure(basePath: dirname(__DIR__))
9+
->withRouting(
10+
web: __DIR__.'/../routes/web.php',
11+
commands: __DIR__.'/../routes/console.php',
12+
health: '/up',
13+
)
14+
->withMiddleware(function (Middleware $middleware)
15+
{
16+
$middleware->append(TeamsPermission::class);
17+
$middleware->alias([
18+
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
19+
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
20+
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
21+
]);
22+
$middleware->group('web', [
23+
\App\Http\Middleware\EncryptCookies::class,
24+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
25+
\Illuminate\Session\Middleware\StartSession::class,
26+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
27+
\App\Http\Middleware\VerifyCsrfToken::class,
28+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
29+
TeamsPermission::class,
30+
]);
31+
$middleware->priority([
32+
\Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
33+
\Illuminate\Cookie\Middleware\EncryptCookies::class,
34+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
35+
\Illuminate\Session\Middleware\StartSession::class,
36+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
37+
TeamsPermission::class,
38+
\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
39+
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
40+
\Illuminate\Routing\Middleware\ThrottleRequests::class,
41+
\Illuminate\Routing\Middleware\ThrottleRequestsWithRedis::class,
42+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
43+
\Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
44+
\Illuminate\Auth\Middleware\Authorize::class,
45+
]);
46+
})
47+
->withExceptions(function (Exceptions $exceptions)
48+
{
49+
//
50+
})->create();

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
"keywords": ["framework", "laravel"],
66
"license": "MIT",
77
"require": {
8-
"php": "^8.1",
8+
"php": "^8.2",
99
"guzzlehttp/guzzle": "^7.2",
10-
"laravel/framework": "^10.10",
11-
"laravel/sanctum": "^3.2",
10+
"laravel/framework": "^11.0",
11+
"laravel/sanctum": "^4.0",
1212
"laravel/tinker": "^2.8",
1313
"laravel/ui": "^4.2",
1414
"php-flasher/flasher-laravel": "^1.13",
1515
"spatie/laravel-activitylog": "^4.7",
16-
"spatie/laravel-permission": "^5.10",
17-
"yajra/laravel-datatables": "^10.0"
16+
"spatie/laravel-permission": "^6.4.0",
17+
"yajra/laravel-datatables": "^11.0"
1818
},
1919
"require-dev": {
2020
"fakerphp/faker": "^1.9.1",
2121
"laravel/pint": "^1.0",
2222
"laravel/sail": "^1.18",
2323
"mockery/mockery": "^1.4.4",
24-
"nunomaduro/collision": "^7.0",
24+
"nunomaduro/collision": "^8.1",
2525
"phpunit/phpunit": "^10.1",
2626
"spatie/laravel-ignition": "^2.0"
2727
},

0 commit comments

Comments
 (0)