Reputation: 1033
this is inside of my Controller:
$a="A";
$b="B";
$res = MyModel::getBook($a,$b);
Inside of "MyModel":
public function scopegetBook($a,$b)
{
var_dump($a,$b);
return null;
}
This only outputs "A" and an object with generic db data, "B" is missing.
Can't scope-methods handle more than 1 parameter? Or do i have to put $a and $b inside an array?
Thank you!
Upvotes: 0
Views: 1585
Reputation: 146269
Actually the first parameter in any scope
method is Query Builder
instance passed by Laravel
and you should use other parameters from the second index, for example:
public function scopeGetBook($query, $a, $b)
{
//...
}
In this method, the first parameter will be passed by Framework and you may use other parameters if you call it like this:
Modelname::getBook($param1, $param2); // Replace Modelname with real Model name
Here the $param1
will be received in the $a
and $param2
will be received in the $b
. Also notice the method name after scope is GetBook
not getBook
.
Upvotes: 3