Чтобы работало
@can('create', Post::class)
<!-- Текущий Пользователь Может Создавать Статьи -->
@endcan
@can('update', $post)
<!-- Текущий Пользователь Может Редактировать Статью -->
@elsecan('create', $post)
<!-- Текущий Пользователь Может Создать Новую Статью -->
@endcan
public function create(Request $request)
{
$this->authorize('create', Post::class);
// The current user can create blog posts...
}
Надо регистрировать политку
/app/Providers/AuthServiceProvider.php
<?php
namespace App\Providers;
use App\Models\User;
use App\Policies\Users\UserPolice;
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',
User::class=>UserPolice::class,
];
/**
* Register any application authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}
<?php
namespace App\Policies\Users;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolice
{
use HandlesAuthorization;
/**
* Determine whether the user can view the user.
*
* @param \App\User $user
* @param \App\User $user
* @return mixed
*/
public function view(User $user, User $user)
{
//
}
/**
* Determine whether the user can create users.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user)
{
//
}
/**
* Determine whether the user can update the user.
*
* @param \App\User $user
* @param \App\User $user
* @return mixed
*/
public function update(User $user, User $user)
{
//
}
/**
* Determine whether the user can delete the user.
*
* @param \App\User $user
* @param \App\User $user
* @return mixed
*/
public function delete(User $user, User $user)
{
//
}
public function before(\App\Models\User $user, $ability)
{
if ($user->isSA()) {
return true;
}
}
}