PHP code example of devcuongnguyen / permissionmanager
1. Go to this page and download the library: Download devcuongnguyen/permissionmanager 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/ */
devcuongnguyen / permissionmanager example snippets
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait; // <------------------------------- this one
use Spatie\Permission\Traits\HasRoles;// <---------------------- and this one
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use CrudTrait; // <----- this
use HasRoles; // <------ and this
/**
* Your User Model content
*/
// in some ServiceProvider, AppServiceProvider for example
$this->app->bind(
\Backpack\PermissionManager\app\Http\Controllers\UserCrudController::class, //this is package controller
\App\Http\Controllers\Admin\UserCrudController::class //this should be your own controller
);
// this tells Laravel that when UserCrudController is requested, your own UserCrudController should be served.
shell
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"
php artisan migrate
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="config"
// then, add the Spatie\Permission\Traits\HasRoles trait to your User model(s)