Mr. Pyramid Mr. Pyramid - 2 years ago 165
PHP Question

how to pass value to controller from view in Laravel

hello folks I'm working on Laravel 5.2 and there I got stuck in a mess.
Actually I want to pass book_id to controller from hyperlink so that whenever use clicks on the link on the basis of book_id controller will return the description of selected book. How to do this?

View

<a href="{{url('bookdetail/'.$value->book_id)}}" class="title" >{{$value->book_name}}</a><br>


Controller

public function viewbook($id)
{
$book_detail= DB::select('select * from book_master where book_id=?',[$id]);
return view('book_detail',['bookdetail'=>$book_detail]);
}


Routes

Route::any('/bookdetail/{id}','BookDetailsController@viewbook');


Also I want to know who to create route for that hyperlink that will pass the book_id to viewbook method

Answer Source

Oops pity me I only need to add a route into routes.php

Route::any('/bookdetail','BookDetailsController@viewbook');

Now it's working fine for me!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download