2
ReflectionException in Container.php line 749:
Class can does not exist
ここroutes.php
から関連する部分です:
Route::get('{user}/profile/edit/{type?}', [
'as' => 'edit',
'uses' => 'User\[email protected]',
'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
;
});
私はゲートを定義するために別のポリシークラスを使用していないためでしょうか? documentation on using Middleware with Routesによると
私は別のポリシークラスをUserに追加し、その上にチェックロジックを移動しようとしました。同じ結果。 –
ミドルウェアは '' middleware '=> [' can:edit-user、user ']に 'can'というクラスとして登録しています。これは実際にあなたのエラーメッセージがあなたに伝えているものです。そのクラスはどこに定義されていますか? – Tom
@thebluefox分かりません。私はLaravelの医者が言うことをします。 (https://laravel.com/docs/5.3/authorization#via-middlewareでチェックしましたか?)Laravelのソースを参照するだけで、Canクラスは表示されません。私はまた、 'can'をauth、authorizeとgateで置き換えようとしました。 –