0

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!

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.