Search flights by subfleet #484 (#506)

* API level search of flights #484

* Add Subfleet to flights page for search
This commit is contained in:
Nabeel S
2020-01-16 17:36:03 -05:00
committed by GitHub
parent d03a77bd4b
commit 2415caab54
11 changed files with 185 additions and 94 deletions
+18 -3
View File
@@ -4,6 +4,7 @@ namespace App\Repositories\Criteria;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;
@@ -17,17 +18,20 @@ class WhereCriteria implements CriteriaInterface
*/
protected $request;
protected $where;
protected $relations;
/**
* Create a new Where search.
*
* @param $request
* @param $where
* @param Request $request
* @param array $where
* @param array [$relations] Any whereHas (key = table name, value = array of criterea
*/
public function __construct($request, $where)
public function __construct(Request $request, $where, $relations = [])
{
$this->request = $request;
$this->where = $where;
$this->relations = $relations;
}
/**
@@ -46,6 +50,17 @@ class WhereCriteria implements CriteriaInterface
$model = $model->where($this->where);
}
// See if any relationships need to be included in this WHERE
if ($this->relations) {
foreach ($this->relations as $relation => $criterea) {
$model = $model
->with($relation)
->whereHas($relation, function (Builder $query) use ($criterea) {
$query->where($criterea);
});
}
}
return $model;
}
}