Home > other >  Why does my custom directive shows parameters error when they are receiving them?
Why does my custom directive shows parameters error when they are receiving them?

Time:04-26

I made a custom conditional directive to determine if a user is allowed or not by the role.

Blade::if('isAllow', function($type, $my_role_id) {
    //dd($type, $my_role_id);
    $rol = Role::where('name', $type)->first();
    return $my_role_id == $rol->id? true : false;
});

I use it this way.

@isAllow('Requestor', Auth()->user()->role_id) All @elseisAllow Reviewed @endisAllow

If into the directive, I put a dd() to see the values, it shows them to me without much problem.

enter image description here

But, when I want to use it in the template, it shows me the following error:

Too few arguments to function App\Providers\AppServiceProvider::App\Providers\{closure}(), 0 passed and exactly 2 expected

I can't find a solution to explain me why is not getting any param when it does. Any help?

CodePudding user response:

you wrote @elseisAllow which is close to the meaning of else if and after @elseisAllow you did not provide arguments so you are getting error . if you don't want to check another condition just use @else

but if you want to check more you should provide arguments that would be something like this : @elseisAllow('Author',auth()->user()->role_id)

  • Related