Laraval does not have this feature built-in.
If you add a limit in the relationship's eager-loading, it will only limit the total set of records it finds, 2 for all parents, not 2 per parent, while even the first parent may have more than 2 images.
But don't worry, Jonas Staudenmeir toke his time developing the missing per-parent limit, see:
https://github.com/staudenmeir/eloquent-eager-limit
Usage:
You need to apply trait to both your models, in your case the models may look like:
class WeddingImage extends Model {
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
class Wedding extends Model {
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
public function weddingimage() {
return $this->hasMany(WeddingImage::class);
}
}
Then simply chain ->limit(2)
in your eager-load query (which seems you already do).