Support the ongoing development of Laravel.io →
Blade Configuration Database
Last updated 2 years ago.
0

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!!

Last updated 9 years ago.
0

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 ' '? 
0

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

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

stuck71 stuck71 Joined 5 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.