How can one pass in the value from a function inside a controller to the render()?
For example:
class NewClass extends Component
{
// $a is being passed in. Already defined
public function DoSomething($a){
return $a;
}
public function render()
{
return view('FirstPage', [
'posts' => NewModel::
// HOW TO PASS IN value of $a
where('Value1', '=', $a)
]);
}
}
EDIT:
I do not know how to call the method of DoSomething inside of the where(), as the $a is not defined in the render().
>Solution :
You must store the value in a class property or variable to be accessible within the render() method.
class NewClass extends Component {
// Declare a class property to hold the value of $a
protected $a;
public function DoSomething($a){
// Assign the value of $a to the class property
$this->a = $a;
return $a;
}
public function render()
{
return view('FirstPage', [
'posts' => NewModel::where('Value1', '=', $this->a)->get()
]);
}
}