Level 10
https://gist.github.com/vluzrmos/3ce756322702331fdf2bf414fea27bcb
From the above link, you will find a way to paginate through an array. Use the paginate function inside the controller.
1 like
I have a This $page Object that has inside news attribute taken while relationship and setted as $page attribute . I want the pagination for this news but I can't set pagination for news because this returns me an error that news Is a type of array, how can I achieve this type of pagination without completely changing the $page object? or other suggestions.
Project\Admin\Models\Page {#1728 ▼
#fillable: array:13 [▶]
#connection: "mysql"
#table: "pages"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:20 [▼
"id" => 7
"parent_id" => null
"lang" => "en"
"parent_lang_id" => null
"title" => "News"
"slug" => "news"
"status" => "published"
"content" => null
"thumbnail" => null
"template" => "8"
"page_type" => "page"
"order" => 2
"meta-title" => "News"
"meta-description" => null
"meta-keywords" => null
"created_at" => "2021-05-17 07:40:18"
"updated_at" => "2021-05-17 07:40:42"
"meta" => array:1 [▶]
"news" => array:5 [▼
0 => Project\Admin\Models\Resource {#1784 ▼
#resource_type: null
#fillable: array:13 [▶]
#connection: "mysql"
#table: "resources"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:16 [▶]
#original: array:15 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:2 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
1 => Project\Admin\Models\Resource {#1783 ▶}
2 => Project\Admin\Models\Resource {#1782 ▶}
3 => Project\Admin\Models\Resource {#1781 ▶}
4 => Project\Admin\Models\Resource {#1780 ▶}
]
"news_categories" => Illuminate\Database\Eloquent\Collection {#1844 ▶}
]
#original: array:17 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:2 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
Please or to participate in this conversation.