Laravel Array to JSON Response From Laravel Controller

Do you know how to make JSON responses from a Laravel array?

As a developer someday we all have to use JSON for creating API’s for frontend applications.  Today I will show you how to make JSON response from an array in Laravel Controller

But if you are using Core PHP you have to follow a different method. I will explain that in this post  [Post link]

So let’s look into some examples of how we can use Laravel array to Json



public function getJson()
{
    $userArray = ['id'=>1, 'name'=>'John', 'email'=>'[email protected]'];
    return response()->json($userArray );
}

Hope this helps.

If you want more awesome Laravel tutorials Checkout this

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

How to get data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Laravel Eloquent WhereNull() and whereNotNull() Example

Do you know how to use WhereNull() and whereNotNull() Laravel Eloquent. In this post, I will explain how to use […]

July 28, 2022

Laravel Array to JSON Response From Laravel Controller

Do you know how to make JSON responses from a Laravel array? As a developer someday we all have to […]

July 28, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now