How to access laravel pagination protected object property?
source link: https://www.laravelcode.com/post/how-to-access-laravel-pagination-protected-object-property
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to access laravel pagination protected object property?
Hello, everyone in this tutorials i will share with you something small but very helpful programing tricks, how to acces laravel pagination protected object property.
recently i was work one laravel application and i need to direct use laravel pagination protected object's property. so, i also share with you.
First, here we show how to look like object get when we get values help of laravel pagination.
Step : 1 Get Data Help Of Pagination.
$getData = User::orderBy('created_at','desc')->paginate(5);
dd($getData)
Output
LengthAwarePaginator {#394 ▼
#total: 4
#lastPage: 1
#items: Collection {#389 ▼
#items: array:4 [▼
0 => IpApprove {#390 ▶}
1 => IpApprove {#391 ▶}
2 => IpApprove {#392 ▶}
3 => IpApprove {#393 ▶}
]
}
#perPage: 5
#currentPage: 1
#path: "http://localhost:8001/ipapprove"
#query: []
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [▶]
}
Look, in the output. now how to access direct total
protected property? you can not access like that. $getData->total
Now, the following example you can see how to handle this typee of situation and how to access any object's protected property in laravel application.
$getData = User::orderBy('created_at','desc')->paginate(5);
$getData = json_encode($getData);
$getData = json_Decode($getData);
// now you can access all the protected property like....
dd($getData->total);
i hope you like this helpful article.
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK