Php Laravel 5.5:授权策略AccessDeniedHttpException此操作未经授权
我创建了一个授权策略,因此我面临这个问题 我已经看到了这些解决方案,但我的问题还没有解决: 代码如下: ArticalesController类中使用的函数:Php Laravel 5.5:授权策略AccessDeniedHttpException此操作未经授权,php,laravel,Php,Laravel,我创建了一个授权策略,因此我面临这个问题 我已经看到了这些解决方案,但我的问题还没有解决: 代码如下: ArticalesController类中使用的函数: public function show(Articale $articale) { $this->authorize('view', $articale); return view('articales.show',compact('articale')); } namespace App\Provider
public function show(Articale $articale)
{
$this->authorize('view', $articale);
return view('articales.show',compact('articale'));
}
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
Articale::class => ArticalePolicy::class,
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}
ArticalePolicy类:
<?php
namespace App\Policies;
use App\User;
use App\Articale;
use Illuminate\Auth\Access\HandlesAuthorization;
class ArticalePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the articale.
*
* @param \App\User $user
* @param \App\Articale $articale
* @return mixed
*/
public function view(User $user, Articale $articale)
{
return $user->id == $articale->user_id;
}
尝试使用您的型号名称,如下所示,将其替换为您的
AuthServiceProvider
替换
Articale::class=>ArticalePolicy::class,
与
'App\Articale'=>'App\Policies\ArticalePolicy',