0
I was looking for a way that the logged-in user could not access another post when editing, just changing the id on url
and implemented something like this, where it will be added to Controller
that manipulates the posts
, edit
, update
etc....
I wonder if anyone has ever needed to implement this in Laravel and as did, the code below works for me, but I look for best implementation practices or something standard Laravel.
Route::get('post/{id}/edit', 'PostController@edit');
public function edit(postRegistro $post, $id)
{
$idUserAutenticate = auth()->id();
$result = DB::table("post")
->whereRaw("id=$id and user_id=$idUserAutenticate")
->count();
if ($result) {
return view('users.postEdit', compact('post'));
} else {
return 'Ação não permitida!!';
}
}
You can easily achieve this level of permission natively in Laravel with Policies and Gates
– Vinicius.Silva
You can use the
Model
?– novic
I have full access to the system, but not much experience with Laravel.
– aguiar677
From what I understand you want this user filter to be dynamic as the user who is logged in? type user 1 is logged in and consequently only records that have relation to user 1 it can mess with?
– novic
This, I checked that when I edit a post the id appears in the url, when changing the id of the url and hit enter, I was able to edit a post of another user.
– aguiar677
Take the ITL ACL course will help you a lot
– Lucas Antonio