I need get two city names with one query:
For example:
City table:
+---------+----------+
| Pana | Name |
+---------+----------+
| THR | Tehran |
| LON | London |
+---------+----------+
In Model: from_city is THR and to_city is LON
public function scopePrintQuery($query, $id)
{
$join = $query
-> join('cities', 'cities.pana', 'flights.from_city')
-> join('cities', 'cities.pana', 'flights.to_city')
-> where('flights.id', $id)
->get([
'flights.*',
'cities.name as from_city'
??? for to_city?
]);
return $join;
}
Now, I need get from_city name and to_city name in this query.
The query does not work with two joins from one table!
How to create this query?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…