How do you feel about the eloquent model? For example, if I have an SQL query as follows:
SELECT one.name
, one.id
, one.name AS sortkey1
, CAST(NULL AS UNSIGNED) AS sortkey2
, CAST(NULL AS UNSIGNED) AS sortkey3
FROM locations AS one
WHERE one.parent_id = 0
UNION ALL
....
In my repository, I will have something like this:
$first = $this->model->where('one.parent_id', '=', 0)
->select('one.name'
, 'one.id'
, 'one.name AS sortkey1'
, DB::raw('CAST(NULL AS UNISIGNED) AS sortkey2')
, DB::raw('CAST(NULL AS UNISIGNED) AS sortkey3'));
So how can you use a model alias. In the above example, the model displays a table of locations and in my eloquent query I want to use it as oneinsteadlocations
source
share