Laravel 8 Response JSON



use Illuminate\Support\Facades\Response;
Route::get('/resp-json',function() {
    $jsonData = [
        [
            'id'=>1,
            'title'=>'Title 1',
            'body' =>'Message details 1',
        ],
        [
            'id'=>2,
            'title'=>'Title 2',
            'body' =>'Message details 5',
        ],
        [
            'id'=>3,
            'title'=>'Title 3',
            'body' =>'Message details 5',
        ],
        [
            'id'=>4,
            'title'=>'Title 4',
            'body' =>'Message details 5',
        ],
        [
            'id'=>5,
            'title'=>'Title 5',
            'body' =>'Message details 5',
        ],
    ];
    return Response::json($jsonData);
    // OR
    // return response()->json($jsonData);
});
OUTPUT:


Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment