Ad
How To Add Where Clause On Implicit Model Binding?
Currently, I have projects using Laravel 5.4 and I am trying to use model binding but I need another where clause, how can I do that?
I am using the implicit model binding on my controller, how can I provide another where clause on that? the where clause is belongs to User input (from The Request instance) which means it can be null
public function show(Request $request, User $user){
$selfish = $request->input('selfish','no');
$user->where('selfish',$selfish);
}
the response is empty or even error, I just wanna know how can I provide another where clause belongs to Request instance.
Ad
Answer
When doing a where() query you then need to use ->get() afterward to gather the information
public function show(Request $request, User $user){
$selfish = $request->input('selfish','no');
$user->where('selfish', $selfish)->get();
return('example.view') //return of somekind you can also do a redirect()->back() if necessary;
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad