I'm trying to protect a route via middleware as described in the doc
When I hit the url, I get:
ReflectionException in Container.php line 749:
Class can does not exist
Here's the relevant part from routes.php
:
Route::get('{user}/profile/edit/{type?}', [
'as' => 'edit',
'uses' => 'User\UserController@edit',
'middleware' => ['can:edit-user,user'],
]);
AuthServiceProvider.php
:
public function boot()
{
$this->registerPolicies();
// ... other definitions
Gate::define('edit-user', function ($user, $subjectUser) {
return
$user->hasRole('manage.user') // if the user has this role, green
||
($user->isAdmin && $user->id == $subjectUser->id) // otherwise if is admin, can edit her own profile
;
});
Maybe it's because I'm not using a separate policy class for defining the gate?
via Attila Fulop