Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

laravel 5.3 - issues #709

Open paulcocis opened 7 years ago

paulcocis commented 7 years ago

route middleware and "routeNeedsRole" method not working.

BadMethodCallException in Macroable.php line 74: Method filter does not exist.

kevosomi commented 7 years ago

@paulcocis did you get a solution? facing the same issue here.

racibaz commented 7 years ago

+1

alihesari commented 7 years ago

@paulcocis @kevosomi @oLDu67 The short answer is no, route filters are not going away entirely in Laravel 5.0 (despite some misleading information out there about this). The functionality still exists to let you use 'before' and 'after' filters on your routes if you would like. The "filters.php" file is no longer provided, but you can still define your filters somewhere else, probably most appropriately in the boot() function of Providers/RouteServiceProvider.php.

However, middleware is now the preferred way to achieve the same functionality. See http://laravel.com/docs/master/middleware for info about how to use it.

Middleware can be implemented to behave like either "before" or "after" filters. And it can be applied to all routes (called "global middleware"), or assigned to specific routes (by adding "'middleware' => 'auth'" for example to your route definitions in your routes.php file.

The only significant limitation of middleware is that it currently doesn't give you a way to pass parameters (as you can with filters). This means you can't do something like "requirePermission:admin" for example. There are currently two ways to deal with this limitation. You can instead just use a route filter instead, just as you did with Larvel 4.2. Or otherwise if you prefer using middleware, this feels like a bit of a hack, but you can pass parameters to the middleware by defining and retrieving custom values added to your route definition as explained at http://blog.elliothesp.co.uk/coding/passing-parameters-middleware-laravel-5/.

2015-05-29 Update: Middleware parameters are available starting with Laravel 5.1.

2015-06-10 Update: Route filters have been deprecated in preference of middleware and will be removed entirely with the release of Laravel 5.2 in December 2015. Retrieved from: http://stackoverflow.com/questions/26373850/filters-in-laravel-5?answertab=votes#tab-top

Zmingg commented 7 years ago

Yes,Route::filter() was removed. I use Middleware take the place of Route filters.

smartman commented 6 years ago

This happens when upgrading from Laravel 5.1 to 5.2 too