PHP code example of yuriy-martini / laravel-authorization

1. Go to this page and download the library: Download yuriy-martini/laravel-authorization library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yuriy-martini / laravel-authorization example snippets




namespace App\Models;

class User
    implements \YuriyMartini\Laravel\Authorization\Contracts\Authorizable
{
    use \YuriyMartini\Laravel\Authorization\Concerns\Authorizable;
}



return [
    \App\Models\User::class => [
        \App\Models\User::class => [
            YuriyMartini\Laravel\Authorization\Enums\Permission::view,
        ],
    ],
];



namespace App\Models\User;

trait Authorizations
{
    public function isViewable(Authorizable $user): bool
    {
        return true; // here: ur BL
    }

    public function isUpdatable(Authorizable $user): bool
    {
        return true; // here: ur BL
    }

    public function isDeletable(Authorizable $user): bool
    {
        return true; // here: ur BL
    }

    public function isRestorable(Authorizable $user): bool
    {
        return true; // here: ur BL
    }

    public function isForceDeletable(Authorizable $user): bool
    {
        return true; // here: ur BL
    }
}



namespace App\Models;

class User
    implements \YuriyMartini\Laravel\Authorization\Contracts\Model
{
    use \App\Models\User\Authorizations;
}


 
namespace App\Policies;
 
class UserPolicy
    extends \YuriyMartini\Laravel\Authorization\Policy
{
    protected static function getModel(): string
    {
        return \App\Models\User::class;
    }
}
shell
php artisan vendor:publish --tag=authorization-defaults-config
shell
php artisan vendor:publish --tag=authorization-models-config