1. Go to this page and download the library: Download genealabs/laravel-governor 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/ */
genealabs / laravel-governor example snippets
// [...]
use GeneaLabs\LaravelGovernor\Traits\Governable;
class User extends Authenticatable
{
use Governable;
// [...]
}
namespace App\Nova;
use Laravel\Nova\Resource as NovaResource;
use Laravel\Nova\Http\Requests\NovaRequest;
abstract class Resource extends NovaResource
{
public static function indexQuery(NovaRequest $request, $query)
{
$model = $query->getModel();
if ($model
&& is_object($model)
&& method_exists($model, "filterViewAnyable")
) {
$query = $model->filterViewAnyable($query);
}
return $query;
}
// ...
}
return [
/*
|--------------------------------------------------------------------------
| Layout Blade File
|--------------------------------------------------------------------------
|
| This value is used to reference your main layout blade view to render
| the views provided by this package. The layout view referenced here
| should s does not match, you
| will only get blank pages when accessing views in Governor.
*/
'content-section' => 'content',
/*
|--------------------------------------------------------------------------
| Authorization Model
|--------------------------------------------------------------------------
|
| Here you can customize what model should be used for authorization checks
| in the event that you have customized your authentication processes.
*/
'auth-model' => config('auth.providers.users.model') ?? config('auth.model'),
/*
|--------------------------------------------------------------------------
| User Model Name Property
|--------------------------------------------------------------------------
|
| This value is used to display your users when assigning them to roles.
| You can choose any property of your auth-model defined above that is
| exposed via JSON.
*/
'user-name-property' => 'name',
/*
|--------------------------------------------------------------------------
| URL Prefix
|--------------------------------------------------------------------------
|
| If you want to change the URL used by the browser to access the admin
| pages, you can do so here. Be careful to avoid collisions with any
| existing URLs of your app when doing so.
*/
'url-prefix' => '/genealabs/laravel-governor/',
];
namespace GeneaLabs\LaravelGovernor\Policies;
use GeneaLabs\LaravelGovernor\Interfaces\GovernablePolicy;
use Illuminate\Auth\Access\HandlesAuthorization;
class MyPolicy extends LaravelGovernorPolicy
{
use HandlesAuthorization;
}
abstract class BasePolicy
{
public function before($user)
{
return $user->hasRole("SuperAdmin")
?: null;
}
public function create(Model $user) : bool
{
return $this->validatePermissions(
$user,
'create',
$this->entity
);
}
public function update(Model $user, Model $model) : bool
{
return $this->validatePermissions(
$user,
'update',
$this->entity,
$model->governor_owned_by
);
}
public function viewAny(Model $user) : bool
{
return true;
return $this->validatePermissions(
$user,
'viewAny',
$this->entity
);
}
public function view(Model $user, Model $model) : bool
{
return $this->validatePermissions(
$user,
'view',
$this->entity,
$model->governor_owned_by
);
}
public function delete(Model $user, Model $model) : bool
{
return $this->validatePermissions(
$user,
'delete',
$this->entity,
$model->governor_owned_by
);
}
public function restore(Model $user, Model $model) : bool
{
return $this->validatePermissions(
$user,
'restore',
$this->entity,
$model->governor_owned_by
);
}
public function forceDelete(Model $user, Model $model) : bool
{
return $this->validatePermissions(
$user,
'forceDelete',
$this->entity,
$model->governor_owned_by
);
}
}
sh
php artisan migrate --path="vendor/genealabs/laravel-governor/database/migrations"
php artisan db:seed --class=LaravelGovernorDatabaseSeeder
sh
php artisan db:seed
sh
php artisan db:seed --class=LaravelGovernorPermissionsTableSeeder
sh
php artisan governor:publish --assets
sh
php artisan db:seed --class="LaravelGovernorUpgradeTo0120"
sh
php artisan db:seed --class="LaravelGovernorUpgradeTo0115"
sh
php artisan db:seed --class="LaravelGovernorUpgradeTo0110"