为什么我的自定义指令在收到参数时会显示错误?
我制作了一个自定义的有条件指令,以确定是否允许用户来通过角色。
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;
});
我这样使用。
@isAllow('Requestor', Auth()->user()->role_id) All @elseisAllow Reviewed @endisAllow
如果进入指令,我将DD()查看值,它向我展示了它们,没有太多问题。
但是,但是,当我想在模板中使用它时,它向我显示以下错误:
Too few arguments to function App\Providers\AppServiceProvider::App\Providers\{closure}(), 0 passed and exactly 2 expected
我找不到解决方案来解释我为什么在执行时不会获得任何参数。有帮助吗?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您写了 @elseisallow ,它接近 else的含义,如果 ,@elseisallow之后,您没有提供参数,因此您会遇到错误。
如果您不想检查其他条件,只需使用 @else ,
但是如果您想检查更多,则应提供类似这样的参数:@elseisallow > user() - > crom_id)
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)