selcukyazar's avatar

Laravel 9 - Breeze - React

Hil Folks, Happy New year to all. I'm am very new in laravel. I created new application with following instructions on site ( laravel9, breeze, react, spatie etc.) I have users, roles, permission table vs. everything seems ok. as I understand I have to use jsx files for user interface. In my sample app I have AuthenticatedLayout.jsx file and I want to access user role. But how.

I am a little bit confused here, actually in users table there is no role field. but I have roles table. Before breeze with react I install only breeze, and I could access @role component.

is there any tutorial or video about this, I found a lot video on youtube but they are not in this scope. Finally I want o implement laravel 9 , react ( breeze, spatie) application with admin, manager and simple user roles, and want to change layouts about for roles.

thank you.

0 likes
2 replies
Alfonso Rodriguez's avatar

From what I understand from the question you want to get the role/permission that corresponds to your current user.

You will not be able to use laravel (blade) components in react or vue files.

It would be a good idea that when you share the user to your AuthenticatedLayout.jsx file, share it something like: $user = Auth::user()->with('roles', 'roles.permissions'), in this way you will have the user along with relationships to its role and nested permissions to the role. Through the relationships you declare in your User model.

There is also https://inertiajs.com/ that makes a lot of these things easier. I recommend the laravel package permission: https://spatie.be/docs/laravel-permission/v5/introduction.

I hope I helped you, I'm still pending!

Please or to participate in this conversation.