Answer the question
In order to leave comments, you need to log in
How to display the last episode in the series list?
Guys please help me figure it out. I have a table of serials and episodes. Communication one to many. On the main page I display a list of series in which for each series it is necessary to display the name of the last added series.
Tried like this:
Serial Model
public function series()
{
return $this->hasMany(Series::class, 'serial_id', 'id');
}
public function getLastSeriesAttribute()
{
return $this->series->first();
}
Answer the question
In order to leave comments, you need to log in
return $this->series()->orderByDesc('номер серии')->first()
->series()
- use a method, not a property, for additional conditions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question