php - Call a field twice in a table with Laravel QueryBuilder
one text
I have a table called collections that has two foreign branches branch_origin_id and branch_destination_id
These obviously relate to a 2nd table called Branches.
What I'm trying to do is, with a single query, get the names of both branches.
My table collections something like this...
Coleccion{
id
nombre,
fecha,
sucursal_origen_id,
sucursal_destino_id
}
Sucursales{
id
nombre
direccion}
The idea is, with Laravel, to make a single query that extracts the name of branch_origin_id and branch_destination_id
$data = DB::table('guia_sucursal')
->join('sucursales','colecciones.sucursal_destino_id','=','sucursales.id')
->select('colecciones.id as id',
'colecciones.titulo as titulo',
'sucursales.nombre as sucursal_destino',)
->paginate(50);
They told me that maybe with aliases I could solve it, but I don't know how...
I am working with Laravel. I clarify, it is obvious that the table that I gave as an example is not 100% the same as the one in the query, I only put the important fields as a reference.
Source