PHP code example of metrixinfo / laravel-permissions

1. Go to this page and download the library: Download metrixinfo/laravel-permissions 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/ */

    

metrixinfo / laravel-permissions example snippets

 
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down(): void
 {
     Schema::disableForeignKeyConstraints();
     Schema::dropIfExists('users');
     Schema::enableForeignKeyConstraints();
 }

use \Metrix\LaravelPermissions\Traits\HasPermissions;
use \Metrix\LaravelPermissions\Traits\HasRoles;

/**
 * Determine whether the user can edit a post.
 *
 * @param  \App\Models\User  $user
 * @param  \App\Models\Post  $post
 * 
 * @return bool
 */
public function update(User $user, Post $post):bool
{
    return $user->id === $post->user_id || Acl::hasEdit('posts');
}


/**
 * Register the Horizon gate.
 *
 * This gate determines who can access Horizon in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewHorizon', function ($user) {
        return Acl::hasRead('horizon');
    });
}
bash
php artisan vendor:publish --provider="Metrix\LaravelPermissions\LaravelPermissionsServiceProvider" --tag="permissions"
bash
php artisan migrate
bash
php artisan acl:clear
bash
php artisan acl:permissions
bash
php artisan acl:roles