You get the part needed, similar to https://gist.github.com/jimgwhit/cbbe5bb0d2556fdc7e37a86d3630239c
A collection would be similar.
Pagination for collection: https://laracasts.com/discuss/channels/guides/paginate-collection-simple-example-guide
when i query the activities table and eager load a relationship, i want the paginated data to contain only the relationship data and not the activity data.
array:12 [
"current_page" => 1
"data" => array:1 [
0 => array:8 [
"id" => 1
"user_id" => "1"
"type" => "created-thread"
"subject_id" => "1"
"subject_type" => "App\Thread"
"created_at" => "2020-09-23T22:15:34.000000Z"
"updated_at" => "2020-09-23T22:15:34.000000Z"
"subject" => array:19 [
"id" => 1
The subject is the eager loaded relationship and i need only the subject data
I know that i can grab the subject using pluck('subject')
collect($paginated)->pluck('subject');
but i can't figure out how to replaced the original paginated data with subjects
Essentially what i want to achieve is the following
$paginated['data'] = $paginated->pluck('subject')
And then finally return $paginated to the view.
Please or to participate in this conversation.