mercredi 6 mars 2019

Laravel eager loading a BelongsTo relation doesn't work

This seems extremely simple and yet it doesn't work:

// Reservations
class Reservation extends Model
{
    public function service()
    {
        return $this->belongsTo('App\Landing');
    }
}

// Service
class Landing extends Model
{
    public function reservation()
    {
        return $this->hasMany('App\Reservation');
    }
}

And then in my controller I have:

$x = Reservation::with('service')->get();
$y = Reservation::all()->load('service');

None of these work. I've tried several ways of loading it and none of them work. It always returns an empty result for the service.

Any other result works fine with eager loading (even with nesting) except te BelongsTo - this one.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire