PHP code example of boss / laravel-district-access

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

    

boss / laravel-district-access example snippets


use Boss\DistrictAccess\Facades\DistrictAccess;
use Illuminate\Support\Facades\DB;

$query = DB::table('vendors');

DistrictAccess::apply($query, 'district');

$vendors = $query->get();

return [
    'user_resolver' => static fn () => auth()->user(),

    'districts_resolver' => static function ($user): array {
        return explode(',', $user->district_role ?? '');
    },

    'super_admin_resolver' => static fn ($user): bool => (int) $user->id === 1,

    'deny_without_districts' => true,
    'deny_raw_condition' => '1 = 0',
];

use Boss\DistrictAccess\Contracts\DistrictAccessContract;

public function index(DistrictAccessContract $districtAccess)
{
    $query = DB::table('vendors');

    $districtAccess->apply($query, 'district');

    return $query->paginate(10);
}

Route::middleware('district.access')->group(function () {
    // protected routes
});
bash
php artisan vendor:publish --tag=district-access-config