Dip Dip - 1 year ago 151
PHP Question

Zizaco / entrust throws error with @permission in blade

I am using a package

Zizaco / entrust
for role-base access control (RBAC).

The user role checks in a view with
, Like wise,

<a class="btn btn-success" href="{{ route('roles.create') }}"> Create New Role</a>

which is equal to,

<?php if (\Entrust::can'role-create') : ?>
<a class="btn btn-success" href="<?php echo route('roles.create'); ?>"> Create New Role</a>
<?php endif; // Entrust::can ?>

But it throws the following error:

Parse error: syntax error, unexpected ''role-create'' (T_CONSTANT_ENCAPSED_STRING) (View: /var/www/rbac/resources/views/roles/index.blade.php)

Answer Source

this is a bug with in the package but you can fix it in your project go to vendors directory there find a entrust directory then from there go to src/Entrusts/EntrustServiceProvider.php

there you find your blade directive code like below

\Blade::directive('permission', function($expression) {
    return "<?php if (\\Entrust::can({$expression}) : ?>";

there you see one starting bracket is missing after can simply add that starting bracket like below

\Blade::directive('permission', function($expression) {
     return "<?php if (\\Entrust::can({$expression})) : ?>";

Or Use with two parenthesis. Like this: @permission(('role-edit')) @endpermission

for further information please check the below link


Note : In prior versions of Laravel, when registering custom Blade directives using the directive method, the $expression passed to your directive callback contained the outer-most parenthesis. In Laravel 5.3, these outer-most parenthesis are not included in the expression passed to your directive callback. Be sure to review the Blade extension documentation and verify your custom Blade directives are still working properly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download