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. :)