Skip to content

Instantly share code, notes, and snippets.

@chengkangzai
Last active November 8, 2022 05:00
Show Gist options
  • Save chengkangzai/7205ca45231b0d0da8358ad9be4cece9 to your computer and use it in GitHub Desktop.
Save chengkangzai/7205ca45231b0d0da8358ad9be4cece9 to your computer and use it in GitHub Desktop.
Policy Stub
<?php
namespace {{ namespace }};
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;
use {{ namespacedModel }};
use {{ namespacedUserModel }};
class {{ class }}
{
use HandlesAuthorization;
public function viewAny({{ user }} $user): Response|bool
{
return $user->can('View Any {{ model }}');
}
public function view({{ user }} $user, {{ model }} ${{ modelVariable }}): Response|bool
{
return $user->can('View {{ model }}');
}
public function create({{ user }} $user): Response|bool
{
return $user->can('Create {{ model }}');
}
public function update({{ user }} $user, {{ model }} ${{ modelVariable }}): Response|bool
{
return $user->can('Update {{ model }}');
}
public function delete({{ user }} $user, {{ model }} ${{ modelVariable }}): Response|bool
{
return $user->can('Delete {{ model }}');
}
public function restore({{ user }} $user, {{ model }} ${{ modelVariable }}): Response|bool
{
return $user->can('Restore {{ model }}');
}
public function forceDelete({{ user }} $user, {{ model }} ${{ modelVariable }}): Response|bool
{
return $user->can('Force Delete {{ model }}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment