I'm trying to add a patch route to routes/api.php
but I get "route not found" even after trying route:cache
. it's registered in route:list
and other routes in that scope are working.
this is my code:
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::group([
'prefix' => 'v1',
'namespace' => 'App\Http\Controllers\Api\V1',
], function() {
Route::group([
'prefix' => '/users',
], function() {
Route::get('/{user}', 'UsersController@show');
Route::patch('/{user}/updateStatus', 'UsersController@updateStatus');
});
});
and this is my code in controller action:
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller {
public function updateStatus(Request $request, User $user) {
# my logic
}
}
the route is registered as /api/v1/users/{user}/updateStatus
but I get 404.
by the way, I'm using laravel 8 and php 7.3
Laravel Artisan Route Command: The route:list Command The route:list command can be used to show a list of all the registered routes for the application. This command will display the domain, method, URI, name, action and middleware for the routes it includes in the generated table.
When deploying your application to production, you should take advantage of Laravel's route cache. Using the route cache will drastically decrease the amount of time it takes to register all of your application's routes. To generate a route cache, execute the route:cache Artisan command:
Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. For example, instead of injecting a user's ID, you can inject the entire User model instance that matches the given ID.
When injecting a model ID to a route or controller action, you will often query the database to retrieve the model that corresponds to that ID. Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes.
I think web server will automatically change url to lowercase so you must use lowercase in laravel route,so you must change "updateStatus" to "updatestatus" or "update-status"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With