cloudcreativity/laravel-json-api

Add a query

a-rsc opened this issue · 2 comments

a-rsc commented

Hi everyone! First of all, sorry for my English! I don't speak and write it very well. I hope you can understand me.
I have a Report resource and this one has a field called created_user. All the users has a role like admin, level1, level2 and level3.
I'd like to implement that in all the actions (index, read, filter, sort...) the level1 and level2 only could see the reports of level1, level2 and level3. And the level3 only could see his reports. So, I need to add a join and a where. Anyway, I don't know how to implement it and which function I must use.
In other words, I need to do a query to select some reports.
Which function must I implement? In the adapter? A specific controller? Can u write the function, please?
I'm not talking about filters. Thank u so much! I'm really on tilt!

This sounds like you need to use a global scope:
https://laravel.com/docs/8.x/eloquent#global-scopes

I'd use middleware to add the global scope so that it is applied on all my API routes.

a-rsc commented

Thank you so much! I've resolved the issue with a global scopes.