0
I am trying to select data from the module table through relationship in the Standard. Where I have 2 tables Module and Activities In activity I have id_modulo and I need to select a column called module title through id.
$status = DB::table('atividades')
->join('modulos', function ($join) {
$join->on('modulos.id', '=', 'atividades.id_modulo');
})
->select('modulos.*')
->get();
$status = $status->titulo;
This script returns me empty array.
Which version of the Laravel you are using ?
– Pedro Henrique
In the bank there really are records and are related correctly?
– Kayo Bruno
If there is more than one record in the query you must recover the value per array, if you wanted the first record, use
->get()[0]
or->first()
– Pedro Henrique
@Pedrohenrique version 5.8
– Richard Nicson
@Kayobruno yes the bank has normal relationship between the tables.
– Richard Nicson
There is only one
modulos.id
for aatividades.id_modulo
?– Pedro Henrique
Yes, @Pedrohenrique
– Richard Nicson
@Richardnicson Pq not use the Eloquent of the Laravel?? The Eloquent will provide you with means to access this information without having to do Join
– PaulinhoCaP