1
I have a table that relates to another one and this relates to some user. How do I so that only the owner of this relation can change/delete the item. Even if I just bring on the form the records that have relation, if by chance I change the identifier that I am going through I will be able to change, so, I was wondering if there’s any way to perform this verification internally in some generic way because I have several cases like this.
I made an answer, but your question is vague, I could elaborate it better and if possible post the excerpt of your code so I rephrase the answer?
– Felipe Paetzold
I have which user is logged in, but how do I check in a generic way during an issue, for example.
– Guilherme Pichok
..during an edition to know if it is really related to the logged in user..
– Guilherme Pichok
You can store user_id in the table you want to compare, and do
Auth::user()->id == $objeto->user_id
, it is even possible to create a middleware for this– Felipe Paetzold
Can you give me an example of how I could do this middleware? I’m not being able to create a logic that allows me to do this in a generic way
– Guilherme Pichok
Like the middleware
Auth
, you place the routes that will pass through it within agroup
with thatmiddleware
and inside it you do the checks. It is an alternative so that you do not create multiple times the same validation.. Have a look at the documentation: https://laravel.com/docs/5.3/middleware– Felipe Paetzold