Solution:
You need to be selecting the key the relationship uses or it won’t be able to match the records back to the parent, in this case you need to also select post_id
, the foreign key:
Post::select('id', 'content')
->with('postMedia:id,link,post_id')
->where('author_id', '=', auth()->user()->id)
->paginate();
“When using this feature, you should always include the
id
column and any relevant foreign key columns in the list of columns you wish to retrieve.”
Laravel 6.x Docs – Eloquent – Relationships – Eager Loading – Eager Loading Specific Columns