Define Columns in Select Method
Define the columns that you want to select after accessing the "belongsToMany" relation which in the example below is the "comments".
Post::first() ->comments() ->select(['comments.id', 'comments.title']);
Otherwise, if you want to retrieve the columns only for the current model then you place the "select" statement method right away.
Comment::select(['id', 'title'])->first()
Or if you prefer to use the "get" method.
Comment::where('id', 1)->get(['id', 'title']);
Leave a reply