Open zeeshan-nxb opened 7 years ago
Try to use double brackets: @role(('retailer'))
I have tried double brackets, but did not work for me.
@ability(('admin', 'create-user,edit-user')) ..... @endability
@manojsharma20 i think, if you will edit the private function bladeDirectives() of vendor/zizaco/entrust/src/Entrust/EntrustServiceProvider.php i.e., add parenthesis () in each directives code i.e.,
\Blade::directive('ability', function($expression) { return "<?php if (\Entrust::ability**({$expression}) ) : ?>"; });
hope your issue will be resolved and Author should provide the best solution in next version or edit the Blade template tutorial for the package users.
private function bladeDirectives()
{
// Call to Entrust::hasRole
\Blade::directive('role', function($expression) {
return "<?php if (\\Entrust::hasRole({$expression})) : ?>";
});
\Blade::directive('endrole', function($expression) {
return "<?php endif; // Entrust::hasRole ?>";
});
// Call to Entrust::can
\Blade::directive('permission', function($expression) {
return "<?php if (\\Entrust::can({$expression})) : ?>";
});
\Blade::directive('endpermission', function($expression) {
return "<?php endif; // Entrust::can ?>";
});
// Call to Entrust::ability
\Blade::directive('ability', function($expression) {
return "<?php if (\\Entrust::ability({$expression})) : ?>";
});
\Blade::directive('endability', function($expression) {
return "<?php endif; // Entrust::ability ?>";
});
}
@ChrisThompsonTLDR , I have done this job like you described. but what will happen when the package will be updated. this code will be overwritten again. so i suggest the @author to fix it for next version updates.
Calling if directives rather than entrust directives worked for me. I tried wrapping the permission name and role name in a second set of round brackets and it still was not working for me. This is my workaround:
<?php $user = Auth::user(); ?>
@if ($user->hasRole(['admin','power-user','finance-manager']))
// Stuff
@if ($user->can('manage-users'))
// Stuff
@endif
@endif
Parse error: syntax error, unexpected ','
code : @ability('r-admin,r-national,r-regional,r-eadmin,r-iadmin,r-sanyojak,r-local','') @endability
Still, it shows error , its working fine on local but it's not working fine on ubuntu server PHP version 5.6.30 .
Default :
private function bladeDirectives() { if (!class_exists('\Blade')) return;
// Call to Entrust::hasRole
\Blade::directive('role', function($expression) {
return "<?php if (\\Entrust::hasRole({$expression})) : ?>";
});
\Blade::directive('endrole', function($expression) {
return "<?php endif; // Entrust::hasRole ?>";
});
// Call to Entrust::can
\Blade::directive('permission', function($expression) {
return "<?php if (\\Entrust::can({$expression})) : ?>";
});
\Blade::directive('endpermission', function($expression) {
return "<?php endif; // Entrust::can ?>";
});
// Call to Entrust::ability
\Blade::directive('ability', function($expression) {
return "<?php if (\\Entrust::ability({$expression})) : ?>";
});
\Blade::directive('endability', function($expression) {
return "<?php endif; // Entrust::ability ?>";
});
}
I'm pretty sure you need to pass role(s) as an array...
@role(['retailer'])`
<h1>this user has the retailer role</h1>
@endrole
In laravel 5.3, Entrust 5.2.x-dev Hello, i have installed the zizaco/entrust latest package and facing the problem when use @role('retailer') in the blade template. error occurs syntax error, unexpected ''retailer'' (T_CONSTANT_ENCAPSED_STRING) after a few attempts i edited the private function bladeDirectives() of vendor/zizaco/entrust/src/Entrust/EntrustServiceProvider.php i.e., add parenthesis ()
before: return "<?php if (\Entrust::hasRole{$expression}) : ?>"; after : return "<?php if (\Entrust::hasRole({$expression})) : ?>"; and also edit for @permission, @ability.
now its working.