Laravel Routes not working like they're supposed to

I am creating an API to save and send events, nothing special about it... I've done it before but for some reason that I can't understand I'm getting this response from a normal route

I need to return an array of collections, nothing wrong about it, in tinker seems to work fine. But my problem doesn't involve data.

I want to do this:

(in routes/api.php)

Route::get('activity/events', function() {
    return 'hi there';
});

But I got a 204 code in Postman with my-site.test/api/activity/events The funny thing is, if I do this:

(in routes/api.php)

Route::get('activity/events/{foo}', function() {
    return 'hi there';
});

I receive the message with no problem with my-site.test/api/activity/events/bar

Am I doing something wrong? I really don't know where to look for an answer

Thanks, everyone!

EDIT: I'm using the most up-to-date versions of everything

Update: The problem I experienced is related to the answer below. I had:

Route::resource('/activity', 'ActivityController');

before: Route::prefix('activity') ...

For anyone reading this, please don't make the same mistake!

Upvotes: 0

Views: 62

Answers (1)

Sunil Kashyap
Sunil Kashyap

Reputation: 2984

Status 204 means that there is no additional content to send in the response payload body.

So try returning some JSON values like

Route::get('activity/events/{foo}', function() {
    return Response()->json(['success' => true], 200);
});

or try Route::prefix

Route::prefix('activity')->group(function () {
  Route::get('events', function() {
        return Response()->json(['success' => true], 200);
    });
});

Upvotes: 2

Related Questions