class Post extends Model
{
public function comments(): HasMany
{
return $this->hasMany(Comment::class)->select('body');
}
}
class Comment extends Model
{
public function attachments(): HasMany
{
return $this->hasMany(Attachment::class);
}
}
Comment just has an empty attachments array. I know, why this happens and that I can solve this, by adding 'id' to the 'select()` method call, but wouldn't it be good if Eloquent knew that it needs this key? Since there's no error message, the mistake is everything but obvious due to the abstraction Laravel and Eloquent have.
If I have something like this
Comment
just has an emptyattachments
array. I know, why this happens and that I can solve this, by adding 'id' to the 'select()` method call, but wouldn't it be good if Eloquent knew that it needs this key? Since there's no error message, the mistake is everything but obvious due to the abstraction Laravel and Eloquent have.