Yes I got the solution to this issue. Please go through the steps I have used.
-Run command php artisan make:provider EntrustCustomServiceProvider
-go to app/Providers/EntrustCustomServiceProvider.php
Use Auth; and Write in the boot function
public function boot() {
\Blade::directive('permission', function($expression) {
return "<?php if (Auth::guard('admin')->user()->can({$expression})) : ?>";
});
\Blade::directive('endpermission', function($expression) {
return "<?php endif; ?>";
});
}
-Add this entry in providers array in config/app.php : App\Providers\EntrustCustomServiceProvider::class,
One more thing, many of the phpstorm users may wonder why these directives are not auto-populated in the editor then please note, whenever we add custom blade directives, we need to add these in the blade plugin of the phpstorm editor. Here is the solution:
-Go to File->settings->php->Blade
-uncheck Default Settings, go to Directives tab.
-Add new directive using +
-Enter the directive name,here permission without using @, check has parameter
-Enter in suffix
-same do for @endpermission without adding any parameters.
I hope this is helpful for someone like me :)