I hope you can help me, I need to make a filter (middleware) say, that only the person who created it can edit a record. It seems easy but I'm new to the subject. I was reading a lot, but they all talk about the user logged in the system, that's what I can do, what I can not do is tell the middleware to look at a field in the table that contains the user's id to verify if it is the same as the user logged in .
I tried the following
if ($request->user_id != auth()->user()->id) {
but the request gives me empty when showing it
if ($request->user_id != auth()->user()->id) {
echo "Request:" . $request->user_id;
echo "<br />";
echo "AUT: " . auth()->user()->id;
\Session::flash('message-danger', 'No está habilitado para realizar esta acción.');
// return redirect()->route('ocprotesis.index');
}
For example, in that AUT code it returns 1, which is fine, but Request returns NOTHING to me
I understand that the middleware is executed before reaching the controller in the route. On the route add the middleware and go through that IF but I can not determine that if the logged in user is NOT who I think this record can not edit it. That's what I need, thanks !!!!