Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

url routing - Laravel API Route - 404

I'm building an API to support an external application. I have added several routes to it with no problem, but suddenly, when I add a new route (acars/delay), I get a 404 error when trying to hit http://myurl.dev/api/acars/delay with a POST request. Here is my api.php file:

Route::post('acars/deactivate', 'APIAcarsController@deactivate');

Route::post('acars/ofp', 'APIAcarsController@ofp');

Route::post('acars/create', 'APIAcarsController@create');

Route::post('acars/pirep', 'APIAcarsController@pirep');

Route::post('acars/mx', 'APIAcarsController@mx');

Route::post('acars/delay', 'APIAcarsController@delay'); // <-- THIS IS THE BROKEN ROUTE

Controller method:

public function delay(Request $request) {
    $acars = AcarsFlight::findOrFail($request->acars_flight_id);
    $delay = AcarsDelay::create([
        ...
    ]);
    return $delay;
}

The other routes work fine, but acars/delay returns a 404 in Postman every time. My php artisan route:list output looks like this:

Output of php artisan route:list

There are no wildcards causing conflicts. I have tried clearing my route cache multiple times, restarting the server, etc. I have also tried moving the broken route to different positions in the api.php file, but no luck. The only thing I can think of is that I recently upgraded the application from Laravel 6 to 8. I read the upgrade guides for v7 and v8, and the only thing I found was that in starting v7, unique route names are required, a requirement I believe I have met. I have verified about a thousand times that I'm using the right URL. Copying+pasting the URL into the browser gives me the extected 405 error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It might be because of something like findOrFail method in your controller. Try to dd at start of your controller and try requesting with Postman again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...