You are asking the database for a column that doesn't exists.
Column not found: 1054 Unknown column 'militants.id' in 'field list'
'militants.id as militant_id',
You need to check your spelling in the query.
I also suggest giving this a read
Hi everyone, I'm having some issues with Laravel's Eloquent queries. This is the situation:
$jeciste = JecJeciste::with('militant.militer', 'militant.sections.regions', 'militant.sections.dioceses')
->select()
->find($id);
The columns of the main JecJeciste table are present, but those of the other tables cannot be found.
Here are the contents of the select
->select(
'jec_jecistes.id as jec_jeciste_id',
'militants.id as militant_id',
'militants.name as militant_name',
'militants.email as militant_email',
'regions.name as region_name',
'dioceses.name as diocese_name'
)
I have this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'militants.id' in 'field list' (SQL: select
jecistes.idasjeciste_id,jecistes.matriculeasjeciste_matricule,militants.idasmilitant_id, fromjecisteswherejecistes.id.
Thank you for your help.
The with method does not do a join. It makes a completely different query. So you cannot do a select. If you want a join, do a join :)
Please or to participate in this conversation.