Policies

Valravn has a base class for policies that automatically check authenticated user has the related permission. there is a roles and permissions management named Horus that can be very handy.

This class contains viewAny, view, create, update, batchUpdate, delete, restore, forceDelete methods by default. for example, if the related model was App\Models\Core\User::class and we requested a specific id, the guessAbility method returns core-user-view ability to authorize.

There is an example of implementation.

 1use Hans\Valravn\Policies\Contracts\ValravnPolicy;
 2
 3class SamplePolicy extends ValravnPolicy {
 4
 5    /**
 6     * Set the related model class
 7     *
 8     * @return string
 9     */
10    protected function getModel(): string {
11        return Post::class; 
12    }
13    
14}