0

I created API in Laravel. Friend that created Mobile app says that he can connect with my data but he requires it to be in JSON format. Here comes my question. Is there any way to change data to JSON format in Api??

Strange is that API gets result in JSON(at least that's what is says)

Example of data in API results

Should I change my API to JSON:API for this to work?

My database works on MySQL if that might be necessary.

My Api routes:

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

// Events

Route::get('/events', function(){
    $date = Carbon::now();
    return Event::where('date_of_event','>=',$date)->get();
});

Route::get('/events/{id}', function($id){

    return Event::findOrFail($id);
});

// Cities

Route::get('/cities', function(){

    return City::all();
});

Route::get('/cities/{id}', function($id){

    return City::findOrFail($id);
});

// Clubs

Route::get('/clubs', function(){

    return Club::all();
});

Route::get('/clubs/{id}', function($id){

    return Club::findOrFail($id);
});

1 Answer 1

2

I use ->json() on the response, there are sure other ways to do it globally.

return response()->json($message);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.