В моем контроллере я получаю список сообщений из модели сообщений.Я пытаюсь добавить фильтр, но фильтры отменяют друг друга.
// Controller
public function __construct(Message $messages)
{
$this->messages = $messages;
}
public function index($filter = null)
{
$messages = $this->messages
->actioned($filter == 'actioned' ? false : true)
->ignored($filter == 'ignored' ? true : false)
->get();
return view('...
}
// Model
public function scopeActioned($query, $actioned = true)
{
$constraint = ($actioned ? 'whereNotNull' : 'whereNull');
return $query->$constraint('ts_actioned');
}
public function scopeIgnored($query, $ignored = true)
{
return $query->where('is_ignored', ($ignored ? 'Yes' : 'No'));
}
Как настроить Eloquent так, чтобы scopeActioned вызывался только в том случае, если для $ filter установлено значение 'actioned' и то же самоедля игнорируемых?