From f8d0075f79b40a0217864ccc058da067727a0483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Mon, 28 Dec 2020 14:50:32 +0300 Subject: [PATCH] skip scope if type is empty --- app/Traits/Scopes.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Traits/Scopes.php b/app/Traits/Scopes.php index a382ae811..1ffd7fb7c 100644 --- a/app/Traits/Scopes.php +++ b/app/Traits/Scopes.php @@ -27,8 +27,14 @@ trait Scopes return; } + $type = $this->getTypeFromRequest(); + + if (empty($type)) { + return; + } + // Apply type scope - $builder->where($model->getTable() . '.type', '=', $this->getTypeFromRequest()); + $builder->where($model->getTable() . '.type', '=', $type); } /** @@ -65,7 +71,7 @@ trait Scopes public function getTypeFromRequest() { - $type = request()->get('type') ?: Str::singular(request()->segment(2, '')); + $type = request()->get('type') ?: Str::singular((string) request()->segment(2)); if ($type == 'revenue') { $type = 'income';