if i hard code what i am searching for in the controller for example:
public function show(Book $book) {
$books= Book::whereClient('stock')->get();
return view('clientbooks.show', compact('book'));
}
but I cant get the variable to pass from the route, like this:
public function show(Book $book) {
$books= Book::whereClient('$client')->get();
return view('clientbooks.show', compact('book'));
}
^^ does not work I get an error : Undefined variable: client. Is there any way to define this from the route and pass it to the controller?
I'm new to laravel and having problems so would appreciate any help or suggestions, thanks!!
i am not sure how/why its working when it shouldnt be because:
public function show(Book $book) {
$books= Book::whereClient('$client')->get();
return view('clientbooks.show', compact('book'));
}
~~~```
you do $books =... but you pass in book/$book which is not your query but whatever the user entered/chose..
aside from that why are you using '$client' whats wrong with $client without ' '?
sorry I wasn't clear ,
public function show(Book $book) {
$books= Book::whereClient('stock')->get();
return view('clientbooks.show', compact('book'));
}
this is the one that was working.
I've just started learning laraval so maybe I'm trying to do it in the wrong way.
What do you mean when you say book is not in my query?
Am I on the right track in trying to do it this way?
If I change the line in routes.php to
return App\Book::whereClient($value)->first();
this returns the first result no problems but if I use get nothing is returned.
routes.php
Route::bind('clientbooks', function($value, $route) {
return App\Book::whereClient($value)->get();
});
controller.php
public function show(Book $book) {
return view('clientbooks.show', compact('book'));
}
thanks for the reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community