0

This is my post method in form.

<form method="POST" action={{" edit ",$user=Auth::user()->id()}} >

This is my function in the controller

public function update(Request $request)
    {
        dd($request->all());
        dd($request->id());
     
    }

And this is the result I'm getting.

array:2 [▼
  "_token" => "VauvcsHlHmxjEwPPjwhIMhm7BnKRAAr20P9lgcLd"
  "id_" => "dfsgdfsg"
]

Now what I am trying to do is get the current users id from the form send it to the function in the controller and update the user's name, but I am only getting the name to be updated not the id as you can see in the result.

  • If you need the id from the URL, [you can get it with `$request->route('id')`](https://stackoverflow.com/questions/33266316/laravel-5-getting-id-from-url). But this is not the way to do this, Laravel makes it easy for you, [look into route model binding](https://laravel.com/docs/8.x/routing#route-model-binding). – Don't Panic Dec 22 '20 at 09:58
  • Does this answer your question? [Laravel 5 getting ID from URL](https://stackoverflow.com/questions/33266316/laravel-5-getting-id-from-url) – Don't Panic Dec 22 '20 at 09:59
  • $request->route('id'); by directly using it in my function? Sorry for lame questions I'm new to this and already freaking out. – Hamza Khan Dec 22 '20 at 13:17
  • C'mon, have a go! :-) Test, debug! If you're not sure, try it, why not in your controller method! But see the link I included about route model binding - taking the id directly from the ID is not the best approach. – Don't Panic Dec 22 '20 at 16:50
  • Sorry, typo - meant *taking the id directly from the URL*. – Don't Panic Dec 23 '20 at 13:48

0 Answers0