Vue.js with Laravel Permission

后端 未结 5 604
旧时难觅i
旧时难觅i 2020-12-31 22:38

I am in the process of integrating Laravel Permission API with Vue.JS frontend. I am using https://github.com/spatie/laravel-permission library for Laravel Permission. I am

5条回答
  •  孤城傲影
    2020-12-31 22:58

    I'm literally working on this exact same thing. I'm thinking of adding a custom Vue directive that would check against the Laravel.permissions array.

    It might even be as simple as

     Vue.directive('can', function (el, binding) {
      return Laravel.permissions.indexOf(binding) !== -1;
    })
    

    I haven't tested this code. Just brainstorming here.

    
    

    I can hold permissions this way:

    window.Laravel =  csrf_token(),
                    'userId' => Auth::user()->id,
                    'permissions' => Auth::user()->permissions()->pluck('name')->toArray()
                ]); ?>
    

提交回复
热议问题