How to Decode Json object in laravel and apply foreach loop on that in laravel

0 votes

I am getting this request.   

 { "area": [
        {
            "area": "kothrud"
        },
        {
            "area": "katraj"
        }
    ]
}

and i want to provide response to this by searching records in database based on above request. how will i decode above json array and use each area field separately.

Sep 30, 2020 in Laravel by kartik
• 37,490 points
3,624 views

1 answer to this question.

0 votes

Hello @kartik,

you can use json_decode function

foreach (json_decode($response) as $area)
{
 print_r($area); // this is your area from json response
}

Hope it helps!!

ThanK you!!

answered Sep 30, 2020 by Niroj
• 82,680 points

Related Questions In Laravel

0 votes
1 answer

Explain validations in laravel and How to validate my application incoming data?

Hey @kartik, In Programming validations are a handy ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
221 views
0 votes
1 answer

What is database migration and how to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
741 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,680 points
514 views
0 votes
1 answer

How to echo to console in Laravel and Artisan?

Hello @kartik, You can try this as this ...READ MORE

answered Apr 3, 2020 in Laravel by Niroj
• 82,680 points
1,622 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
6,827 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
791 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
594 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,680 points
7,211 views
0 votes
1 answer
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,680 points
6,101 views