I’m a beginner so I’m still struggling with this.
I need your help to convert this query to Laravel’s query
but apperently this one doen’t work even in PhpMyAdmin.
SELECT `candidats.id`
FROM `candidats`,
`candidatures`
WHERE `candidats.id` = `candidatures.candidat_id`
ORDER By `candidatures.date_depot`;
What I want to do is to display all the candidates ordred by etat
but this etat
that belongs to candidatures
table
In Candidat
Model :
class Candidat extends Model
{
use HasFactory;
protected $table = 'candidats';
protected $fillable = [
'id_service',
'demande',
'nom',
'prenom',
'email',
'adresse',
'date_naissance',
];
public function candidatures()
{
return $this->hasMany(Candidature::class);
}}
In Candidature
Model :
class Candidature extends Model
{
use HasFactory;
protected $table = 'candidatures';
protected $fillable = [
'candidat_id',
'date_depot',
];
public function candidat()
{
return $this->belongsTo(Candidat::class, 'candidat_id');
}
}
Thank you in advance.
2
Answers
well I've tried
and it works
Try to get like this