所以在AuthServiceProvider
我正在做以下事情:
namespace App\Providers;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
\App\Post::class => PostPolicy::class
];
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
}
PostPolicy
namespace App\Policies;
use App\Post;
use App\User;
class PostPolicy
{
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
}
public function view(User $user)
{
dd('he was here');//This line NEVER gets executed.
return $user->type === 'user';
}
}