To clarify, I'd like to be able to use this in a way similar to the @can blade directive and its relatives.
Accessing User roles from Vue in an SPA
Maybe I haven't found the right articles to guide me in the right direction, but I haven't been able to figure out a solution to my problem.
I'd like to be able to use a package like Entrust to handle User roles, but I need to be able to access these roles and use them to change available sections within a Vue SPA, and I haven't figured out the best way to work with this situation.
If someone can recommend an article to help me with this problem or give me a general idea of the way to handle it.
Thanks!
Thanks to @silverxjohn for leading me in the right direction.
What I ended up doing was adding a roles array in the window.Laravel section in my blade layout. Then, I could set that to this: {!! Auth::user()->roles->pluck('name') !!}, and finally put the code below in my bootstrap js file to give me Auth.is('role') capabilities.
window.Auth = {
is(role) {
return (Laravel.user.roles.indexOf (role) != -1);
}
}
Perhaps this isn't the best solution, but it worked for me.
Please or to participate in this conversation.