This is a example to create a personal laravel directive
use Illuminate\View\Compilers\BladeCompiler;
protected function registerBladeExtensions()
{
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
$bladeCompiler->if('canActAsTgo', function ($permission_user) {
if (\Gate::allows('onlyOwner')) {
return true;
}
$getUser = auth()->user()->asTgoUserInsideAccount;
if(!isset($getUser)){
return false;
}
$arr = [];
foreach ($getUser->permissions as $permission){
if($permission->name == $permission_user){
$arr = ["name" => $permission->name];
}
}
$newCollect = collect($arr);
return $newCollect->contains($permission_user);
});
});
}
$this->registerBladeExtensions();