Я использую код для фильтрации через $ _GET
$this['painting'] = Painting::
where('p_price',$p_price)->
where('p_created',$p_created) ->
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
URL-адрес mysite/page.php?type_id=3&p_created=1996
Все в порядке.
Но если у меня есть пустой параметр, у меня нет результата. Например, URL-адрес mysite/page.php?type_id=&p_created=1996
или URL-адрес mysite/page.php?type_id=3&p_created=
возврат пустой строки
Теперь я использую что-то подобное
if (!$p_created and !$type_id){
$this['painting'] = Painting::
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif (!$p_created and $type_id){
$this['painting'] = Painting::
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif ($p_created and !$type_id){
$this['painting'] = Painting::
where('p_created',$p_created) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif ($p_created and $type_id){
$this['painting'] = Painting::
where('p_created',$p_created) ->
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
Как я могу это исправить?