I’m learning Laravel on an existing 11.29.0
project.
I have two routes defined:
//api.php
Route::get('/items/approved', [ItemController::class, 'approved']);
Route::get('/items/{id}', [ItemController::class, 'show']);
In my controller I have this:
//ItemController.php
namespace AppHttpControllers;
use IlluminateHttpResourcesJsonAnonymousResourceCollection;
use AppHttpResourcesItemResource;
class ItemController extends Controller{
//MARK: Approved
public function approved(): AnonymousResourceCollection
{
error_log('inside approved');
//...
}
//MARK: Show
public function show($id): ItemResource|JsonResponse
{
error_log('inside show');
//...
}
}
When I do a GET
request to /items/approved
it always hits the show($id)
function.
Shouldn’t the fact that /items/approved
comes before /items/{id}
make it so the approved()
function is called? What am I missing?