Lumen 8 returns Bad Exception for GET actions with parameters

  lumen, php

Im currently using Lumen 8. Im having issues with routing. The controllers work fine for get methods without parameters but I get a "Bad Routes exception" when I pass parameters

$router->get('/accounts', '[email protected]');
$router->get('/accounts/{id:[d]+}', '[email protected]');

For example for the first route, localhost/accounts it displays the required data. The second route however when localhost:8002/accounts/1 it returns the error.

The routes are defined in an AccountsController

public function index(){
    $data = $this->collection(Account::all(), new AccountsTransformer());
    return response()->json($data);
}

public function show($id){
    try{
        return $this->item(Account::query()->findOrFail($id), new AccountsTransformer());
    } catch (ModelNotFoundException $e){
        response()->json(['error'=>['message'=>'Account not found']]);
    }
}

Source: Ask PHP

LEAVE A COMMENT