Reputation: 3835
I am still learning laravel
I have tables like this:
Item->ID
Item->User_ID
Now I get a selected item and set its ID as a session variable using this code:
public function get_item($id){
$selected_item = item::where('id',$id)->where('User_ID',Auth::user()->id)->first
$request->session()->put('item_id', $selected_item->id);
}
Now with this SESSION variable I can do other things such as delete, edit etc:
public function delete_item(Request $request)
{
Item::where('id,$request->session()->get('item_id'))->delete();
}
Now some people has told me that this is good practice because I only reach the Database once and have it set until I select another item. Some people have said that I should still just use more Middleware instead of setting SESSION variables. Since I get such diverse opinions, would anyone tell me if this way is correct?
Upvotes: 1
Views: 720
Reputation: 1967
Session is a wrong way. You have to pass id as query string and then perform edit, delete or you can use ajax and on button click you can pass the item ID and then perform operations like edit, delete.
Upvotes: 1