mercredi 21 juin 2017

Laravel 5.4 - Prefixing and applying two middlewares for a multi-tenant application's routes

I'd like to group /account/{account_id} as well as protect every route inside it with the auth middleware and a middleware that will check if the logged user has access to this account. Unfortunately it's not working.

Here is my code

web.php:

Route::group(['middleware' => 'auth'], function () {
    Route::group(['prefix' => 'account/{account}', 'middleware' => 'userHasPermissionForAccount'], function() {
        Route::group(['prefix' => 'posts'], function () {
            Route::get('{post}', 'PostsController@index')->where([
                'post' => '\d+'
            ]);
        });
        // more routes here...
    });
});

app/http/kernel.php

// ...
protected $routeMiddleware = [
    // ...
    'userHasPermissionForAccount' => \App\Http\Middleware\UserCanAccessContent::class,
];

It don't even triggers the code inside my custom middleware and I don't understand why.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rWKRBp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire