Trouble getting $id from session in laravel
Trouble getting $id from session in laravel
I am trying to pass on the value $id through my href to the next page
Route:
Route::get('/offer-me/{id}', 'OffersController@create')->name('project.detailed');
From View:
<a href="{{ route('project.detailed', [$product->id]) }}"><button class="btn btn-success">View</button></p></a>
When I go to localhost/projectp0/public/offer-me/2 .... There is no $id value?
{"_token":"dSxgM8wTlpNxhDKsqj713KMy656bg8XAU5Q2sqe4","_previous":{"url":"http://localhost/projectp0/public/auction"},"_flash":{"old":,"new":},"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d":1}
To get that view i Run:
$data = session()->all();
return($data)
$url = route('routeName', ['id' => 1]); (note the associative array with the id key mapping to the value)– drew010
Jul 1 at 23:53
$url = route('routeName', ['id' => 1]);
id
@HCK I have a form on the other end i want to store the value in $product->id= $id
– user9820353
Jul 1 at 23:54
@drew010 same error. No $id value is shown even when i try $data = $request->session()->get('id'); and return it
– user9820353
Jul 1 at 23:57
Looks like there is no
$product anywhere in the data passed to the view. Once that is passed in, the URL route helper will generate the URL correctly.– drew010
Jul 2 at 0:00
$product
route
3 Answers
3
The {id} parameter lives in the request, and not in the session.
{id}
It will be available as request()->id.
request()->id
The Returned Data set is your session data. Session data is not storing the data you send from a Get Method. Get method send Data with the URL,
So create method in Offer Controller should be like this.....
public function create($id){
dd($id);
}
Then You Can see What is the value passed for the $id,
You could use
public function create($id)
{
}
It is better to have a create route use a post route
in which case you should be able to access it through the request
public function create(Request $request)
{
$id = $request->id
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is your use case? That could be helpful to get you a proper solution/alternative.
– HCK
Jul 1 at 23:46