I have two tables: dayreport and dayreport_events, with a one-to-many relationship.
class DayreportEvent extends Model
{
public function dayreport(){
return $this->belongsTo('App\Models\Dayreport');
}
In this case I want to query all dayreportevents to get Instances of the DayreportEvent class. But from this instance I want to have access to the Dayreport instance. To avoid an individual database query for each row, I want to use the with() method in the query builder:
DayreportEvent::with('dayreport')->get();
But with this query I get the following error:
Call to undefined relationship [App\Models\Dayreport] on model [App\Models\DayreportEvent].
Why can't I do it like this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire