Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

Laravel 5.3 blade translation error @role() #657

Open marijnhurkens opened 8 years ago

marijnhurkens commented 8 years ago

I'm currently upgrading to Laravel 5.3 and I found a problem with some of my templates when using the @role() directive from Entrust.

The error I get:

Parse error: syntax error, unexpected ''admin'' (T_CONSTANT_ENCAPSED_STRING)

My view (testcase):

@role('admin')
    <h1>test</h1>
@endrole

The rendered cached view:

<?php if (\Entrust::hasRole'admin') : ?>
    <h1>test</h1>
<?php endif; // Entrust::hasRole ?>

Which off course gives a syntax error.

This could be an issue unrelated to Entrust, but I'm unable to find out what the problem is.

marijnhurkens commented 8 years ago

I found the problem in the upgrade guide:

Custom Directives

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.

I will try to create a pull request.

SequelONE commented 8 years ago

I have error with Fix

BadMethodCallException in Builder.php line 2437: Call to undefined method Illuminate\Database\Query\Builder::hasRole()

marijnhurkens commented 8 years ago

I can't reproduce that here, and I can imagine the fix won't work on pre 5.3 Laravel installations. What would be the best way to solve this?

SequelONE commented 8 years ago

Solved a problem here installing this package https://github.com/santigarcor/laratrust

mhanoglu commented 8 years ago

Use with two parenthesis. Like this:

@role(('admin'))
...
@endrole
@permission(('role-edit'))
...
@endpermission
kierenblack commented 8 years ago

The file EntrustServiceProvider needs changed. \Blade::directive('permission', function($expression) { return "<?php if (\Entrust::can{$expression)) : ?>"; }); needs to be

\Blade::directive('permission', function($expression) { return "<?php if (\Entrust::can({$expression})) : ?>"; }); if you add the () around {$expression } it works. you also need to change it for role and ability.

aescasio commented 8 years ago

Hi @kezzab25,

Just want to clarify, is your resolution works on Laravel 5.3? Because I also found resolution here

What would be the best solution, modifying the class or use double parenthesis as what @marzochi advice?

I was using Laravel 5.2 before with Zizaco/Entrust and want to upgrade to 5.3, but before doing that just want some clarification before diving into it.

kierenblack commented 8 years ago

The double (( would work but I put in the the service file so that I wouldn't have to go and change it in multiple blade files.

On Sep 25, 2016 8:57 PM, "Angelo Escasio" notifications@github.com wrote:

Hi @kezzab25 https://github.com/kezzab25,

Just want to clarify, is your resolution works on Laravel 5.3? Because I also found resolution here https://github.com/Zizaco/entrust/issues/653

What would be the best solution, modifying the class or use double parenthesis as what @marzochi https://github.com/marzochi advice?

I was using Laravel 5.2 before with Zizaco/Entrust and want to upgrade to 5.3, but before doing that just want some clarification before diving into it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Zizaco/entrust/issues/657#issuecomment-249463348, or mute the thread https://github.com/notifications/unsubscribe-auth/AERrge6Q3FqVETJI6Uc0vr7uhDYluC14ks5qtyaIgaJpZM4J6VQY .

arfanmukhtar commented 7 years ago

@marzochi Thanks

arfanmukhtar commented 7 years ago

it may help you

user like this : `@role(('admin'))

test

@endrole`