Car-Repairs-Shop/app/Providers/BladeServiceProvider.php
sackey e839d40a99
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
Initial commit
2025-07-30 17:15:50 +00:00

61 lines
1.7 KiB
PHP

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
class BladeServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
// Blade directive for role checking
Blade::if('hasrole', function ($role, $branchCode = null) {
return auth()->check() && auth()->user()->hasRole($role, $branchCode);
});
// Blade directive for permission checking
Blade::if('hasPermission', function ($permission, $branchCode = null) {
return auth()->check() && auth()->user()->hasPermission($permission, $branchCode);
});
// Blade directive for checking any permission
Blade::if('hasAnyPermission', function ($permissions, $branchCode = null) {
if (!auth()->check()) return false;
if (is_string($permissions)) {
$permissions = explode('|', $permissions);
}
return auth()->user()->hasAnyPermission($permissions, $branchCode);
});
// Blade directive for checking any role
Blade::if('hasAnyRole', function ($roles, $branchCode = null) {
if (!auth()->check()) return false;
if (is_string($roles)) {
$roles = explode('|', $roles);
}
return auth()->user()->hasAnyRole($roles, $branchCode);
});
// Blade directive for admin check
Blade::if('isAdmin', function () {
return auth()->check() && auth()->user()->hasRole('admin');
});
}
}