Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel如何访问javascript文件中的身份验证。_Javascript_Php_Laravel - Fatal编程技术网

Laravel如何访问javascript文件中的身份验证。

Laravel如何访问javascript文件中的身份验证。,javascript,php,laravel,Javascript,Php,Laravel,在我的@yield('scripts')部分中,有一个javascript调用,其中我仅在用户是管理员时显示一个按钮 我想把javascript放在我的库中,因为它被多次使用。但是,当我试图在库中包含此部分时,Blade/php不起作用myApp.js javascript部分 BootstrapDialog.show({ title: 'Age Not Met', message: 'The attendee does not meet the age reguirement for

在我的
@yield('scripts')
部分中,有一个javascript调用,其中我仅在用户是管理员时显示一个按钮

我想把javascript放在我的库中,因为它被多次使用。但是,当我试图在库中包含此部分时,Blade/php不起作用
myApp.js

javascript部分

BootstrapDialog.show({
   title: 'Age Not Met',
 message: 'The attendee does not meet the age reguirement for this program.',
    type: BootstrapDialog.TYPE_WARNING,
 buttons: [
          @if (Auth::user()->hasRole('admin')||Auth::user()->hasRole('programmer'))
          {
              label: 'OVERIDE',
           cssClass: 'btn-danger',
             action: function(dialogItself){
                     checkbox.prop('checked', true);
//...rest irrelevant
我试图在布局中使用一个变量来替换blade/php调用,但该变量为空。我还意识到我不能仅仅用
if(isAdmin)
替换刀片,因为它在一个函数参数中…我如何才能让按钮仅为管理员显示

在布局中

<script>
var isAdmin = {{ (Auth::user()->hasRole('admin')||Auth::user()->hasRole('programmer')) }}
</script>

var isAdmin={{(Auth::user()->hasRole('admin')| | Auth::user()->hasRole('programmer')}

如果(isAdmin)正确,则使用
的方法。您应该像在视图中那样定义它,然后:

var varButtons = []
if(isAdmin){
          varButtons = [{
              label: 'OVERIDE',
           cssClass: 'btn-danger',
             action: function(dialogItself){
                     checkbox.prop('checked', true);   
                    }
                }]; 
}
BootstrapDialog.show({
       title: 'Age Not Met',
     message: 'The attendee does not meet the age reguirement for this program.',
        type: BootstrapDialog.TYPE_WARNING,
     buttons: varButtons

如果您计划让javascript决定按钮是否显示,您可以让按钮始终可见,因为您的用户将能够以任何方式显示它。