I've got problem with selection from my database.
This is how my query should look like:
SELECT `deads`.`id`, `graves`.*, `places`.`row`, `places`.`place`, `places`.`id_quarter`, `places`.`occupied` FROM `deads` LEFT JOIN `graves` ON `deads`.`id_grave` = `graves`.`id` LEFT JOIN `places` ON `graves`.`id_place` = `places`.`id` WHERE `places`.`id_quarter` = '1' AND `places`.`occupied` = '1'
My Dead model:
public function graves()
{
return $this->belongsTo(Grave::class,'id_grave');
}
My Grave model:
public function places()
{
return $this->belongsTo(Place::class,'id_place');
}
public function deads()
{
return $this->hasMany(Dead::class);
}
My Place model:
public function quarters()
{
return $this->belongsTo(Quarter::class,'id_quarter');
}
public function graves()
{
return $this->hasOne(Grave::class,'id_grave');
}
I can't get the idea, how I can write this as eloquent select. I want to bypass future injection problems. Is there any way to get it smoothly or should I leave it as RAW SQL query? How to convert it to an array like I get it when I use eloquent?