I have this site and one of its pages creates a simple list of people from the database. I need to add one specific person to a variable I can access.
How do I modify the return $view->with('persons', $persons);
line to also pass the $ms variable to the view?
function view($view) { $ms = Person::where('name', 'Foo Bar'); $persons = Person::order_by('list_order', 'ASC')->get(); return $view->with('persons', $persons); }
If your using laravel, try this: return view('app-student. app-student dashboard',compact('education_level_data','student_data',.......n)); where by: 1. education_level_data----first-parameter 2. student_data ----second parameter NB: And you can pass more parameters as much as you can.
Possible solution is that you define private/protected variables as a and b within the class and in the method totalStocks() you can set values to them. So you can access $this->a and $this->b as properties of the class whenever class is in use. Save this answer. Show activity on this post.
You have to create the method in controller class as a static method and you can directly call the controller's method by specifying the full path of controller in view file. You can also pass data from view to controller using anchor tag with route method and get in controller's method.
Just pass it as an array:
$data = [ 'name' => 'Raphael', 'age' => 22, 'email' => '[email protected]' ]; return View::make('user')->with($data);
Or chain them, like @Antonio mentioned.
This is how you do it:
function view($view) { $ms = Person::where('name', '=', 'Foo Bar')->first(); $persons = Person::order_by('list_order', 'ASC')->get(); return $view->with('persons', $persons)->with('ms', $ms); }
You can also use compact():
function view($view) { $ms = Person::where('name', '=', 'Foo Bar')->first(); $persons = Person::order_by('list_order', 'ASC')->get(); return $view->with(compact('persons', 'ms')); }
Or do it in one line:
function view($view) { return $view ->with('ms', Person::where('name', '=', 'Foo Bar')->first()) ->with('persons', Person::order_by('list_order', 'ASC')->get()); }
Or even send it as an array:
function view($view) { $ms = Person::where('name', '=', 'Foo Bar')->first(); $persons = Person::order_by('list_order', 'ASC')->get(); return $view->with('data', ['ms' => $ms, 'persons' => $persons])); }
But, in this case, you would have to access them this way:
{{ $data['ms'] }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With