How to convert object to array in Laravel 5?By Hardik Savani | June 2, 2016 | | 1902 Viewer | Category : Laravel
Share this post:
If you require to convert object data from db into array then you can do it using DB facade and Model Eloquent. Sometimes we need to give array data only so we must get array data from db. I have two examples so it can helps you.
In first example, If you use Model Eloquent for get data from database then you can do it using toArray(). toArray() will help to convert object into array data. So let's see bellow example and check it.
$users = User::get()->toArray();
In this example, if you use DB facade for getting data then it's different from above because when i was try to convert object into array then i can't do using direct toArray() but i found solution how to do it. You can check bellow example.
$users = DB::table("users")->get();
Tags :Source Code Example Laravel Laravel 4 Laravel 5 Laravel 5.2 Laravel Eloquent Object to Array toArray()
- How to change Bootstrap Datepicker with specific date format?
- How to clear log file using command in laravel 5 ?
- Laravel 5 - How to prevent browser back button after user logout?
- AngularJS - update bind ng-model input value from Jquery Code
- Jquery - draggable sortable table rows example demo with bootstrap
- Laravel 5 create and download zip file example using chumper/zipper composer package
- Jquery highlight search text in div using highlight JS with example
- Laravel 5 select with sum query example