PHP code example of nikan2010 / accessible-resources

1. Go to this page and download the library: Download nikan2010/accessible-resources 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/ */

    

nikan2010 / accessible-resources example snippets


'resources' => [
    'product' => \App\Models\Product::class,
    'category' => \App\Models\Category::class,
],

'admin_role' => 'admin',

use AccessibleResources\Traits\HasAccessibleResources;

class User extends Authenticatable
{
    use HasAccessibleResources;
}

$user->accessibleResources(\App\Models\Product::class)->attach($productId);

$orders = Order::query()->withAccessibleTo(
    auth()->user(),
    'product', // نام رابطه
    'product', // کلید تعریف‌شده در فایل config
    'product_id' // (اختیاری) برای روابط belongsTo
)->get();

$user->clearCachedAccessibleResourceIds(\App\Models\Product::class);
bash
php artisan vendor:publish --tag=accessible-resources
php artisan migrate