I have problem to get value of protected array in my laravel project and want to save my data into database using foreach. I used to print_r
my data
print_r($request->data);
Here is my array data:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[id] => 900
[zone_id] => 1
[account_id] => 2
[size] => 23474836488
)
[1] => stdClass Object
(
[id] => 9001
[zone_id] => 2
[account_id] => 2
[size] => 23474836488
)
)
)
Is there any solution of my problem?
You are getting an array in the object.
You can access it as below.
foreach($request->data as $data){
echo $data->id;
echo $data->zone_id;
echo $data->account_id;
echo $data->size;
}
In Laravel, whenever you'll execute DB query or fetch records from database it will return you this kind of object.
If you want to see the object to array the as per @Ammar Faizi Comment you can convert it into array. $request->data->toArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.