Closed ThomasCedrini closed 8 years ago
That is not possible. Scopes are shortcuts to frequently used simple queries.
You should probably add a new method to your mapper instead.
Actually, it should work. The only thing to note is that the $query
object will always be the first parameter: https://github.com/vlucas/spot2/blob/master/lib/Query.php#L793
You can just define extra parameters on your scope as normal, after the required $query
argument:
<?php
namespace SpotTest\Mapper;
use Spot\Mapper;
use Spot\Query;
class Event extends Mapper
{
/**
* Custom scopes applied to Spot\Query
*
* @return array
*/
public function scopes()
{
return [
'page' => function (Query $query, $page = 1, $items = 20) {
return $query->limit($items)->offset($page > 0 ? $page * $items : 0);
}
];
}
}
And use it like this:
$mapper->where(['type' => 'post'])->page(1);
Hi !
I want to define a scopes in my mapper but I need to pass some arguments. How can I do that?
Thanks !
PS : Your project is awesome !!