Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lvstross's avatar

API Route Status 404 Even Though It Exists

Hey everyone,

I'm having a hard time understanding why one of my API routes is returning a 404 status code after a get ajax request even though the route is clearly defined in the api.php page. I'm working with version 5.4 and I'm using Vue and Vuex to handle my interface.

The purpose behind this request is to send two dates, a start date and an end date, so that I can fetch the results in my model that have dates in between those two given dates. It's essentially like a report where the user can find all their entries between two dates.

Here is the Route:


Route::group(['middleware' => 'auth:api'], function(){

   Route::get('invoices/report', 'InvoicesController@betweenDates');

}

The Route is showing up on my Routes list:


GET|HEAD  |  api/invoices/report  |  App\Http\Controllers\InvoicesController@betweenDates |  api,auth:api,auth

And her is the Request: The request is in an actions.js file which is being imported into a modules file for my vuex store. This is specifically where it is failing. I'm getting a status code of 404 with this request.


export const dateRangeSearch = ({ commit }) => {

    return new Promise((resolve, reject) => {

        axios.get('api/invoices/report')

        .then((response) => {

               // code block

        }).catch((error) => {

              // code block

        });

    });

};

And here is my controller for that route:


    public function betweenDates(Request $request)

    {

        $start = $request->input(['start']);

        $end = $request->input(['end']);

        $invoices = DB::table('invoices')

                    ->whereBetween('date', [$start, $end])

                    ->get();

        return $invoices;

    }

I have no idea why this is happening. All of my other API routes work and this is the only one that is not working. My thought was maybe I'm using the wrong verb for the request but since this is a search based request, I'm failing to see why a get request wouldn't work.

The link to the repo is Here.

thanks for you time and help. :)

0 likes
3 replies
robrogers3's avatar

So the network tab says 404, and the same goes for hitting it in your browser directly?

If so, open your Handler and start dd stuff , better use dump($exception), etc.

it sucks to find out what's happening, the pipeline and closures make it hard to track down.

let me know what you find.

also install the laravel debug bar. super helpful.

lvstross's avatar

Hey robrogers3, thanks for the reply, I decided to take a different approach and declare the parameter onto the route as wild cards and use them as parameters like that and it ended up working. :)

Please or to participate in this conversation.