I have this code for example:
$sheet_data=Model::where('workbook_ord',"$workbook")->get();
I want to assign where
block to Model
dynamically like this:
$qry = 'where("workbook_ord","$workbook")';
and I want the query to become like this:
$sheet_data=Model::eval($qry)->get();
I know if I want to use method name dynamically, I can use that like this:
$qry = "where";
$sheet_data=Model::$qry('workbook_ord',"$workbook")->get();
But, I want to execute function including parametera defined in a string.
I hope there must be a way to do that.
Not exactly the solution for the problem you asked for but you can use magic methods to achieve something similar.
For your specific case you can use __callStatic()
where you can call any pseudo method to be parsed inside __callStatic
with the correspondent arguments.
class Model
{
public static function __callStatic($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling static method '$name' "
. implode(', ', $arguments). "
";
}
}
Model::where('workbook_ord', 'test')
// will echo: Calling static method 'where' workbook_ord, test