Passing {id} when button is clicked


Passing {id} when button is clicked



I have setup a controller - product which allows me to look up a product


url.com/product/{id}



When I click a button on the product page. say, to add to cart which takes me to another page. What is the best way to pass on this {id}. Becuase then I want to reference this $id in a controller to look up pricing via .



$price = Prices::where('id',$id)


$price = Prices::where('id',$id)



Is this a good method?



Route::get('/prices/{id}', 'PriceController@lookup');


Route::get('/prices/{id}', 'PriceController@lookup');



then


<a href="/make-offer/{{$listings->id}}"><button class="btn btn-success">View Price</button></a>



Only issue with this is I get Missing required parameters for [Route: ] [URI:/prices/{id}





check whether $listings->id is empty. or $listings is a collection?
– ab_ab
Jul 1 at 12:01



$listings->id


$listings





View the html in debugger in browser and let us know what the link actually shows as. Plus your question references three different routes, /product, /make-offer, and /prices. Which are you trying to hit in your link?
– OneLiner
Jul 1 at 16:14




1 Answer
1



change


<a href="/make-offer/{{$listings->id}}"><button class="btn btn-success">View Price</button></a>



to


<a href="/prices/{{$listings->id}}"><button class="btn btn-success">View Price</button></a>






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.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?