8000 Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id] · Issue #1784 · dingo/api · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id] #1784
Open
@hsariaslan

Description

@hsariaslan

| Defining routes with parameter | ---
| Bug? | no
| New Feature? | no
| Framework | Laravel
| Framework version | 8.54
| Package version | 3.0.0
| PHP version | 7.4.22

Actual Behaviour

Hey everyone, I am new to Dingo API and following documentation but I am struggling with creating routes with parameters. When I send a request to localhost/users it works as expected and response me all users in database. But when I try to send a request to show a specific user via id parameter, it returns 500 error with following message, also if I run a php artisan command it gives me the same error:
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id].

Steps to Reproduce

api routes:

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function ($api) {
    $api->get('users/{id}', ['as' => 'users.show', 'uses' => 'App\Http\Controllers\Api\V1\UserController@show']);
    $api->get('users', ['as' => 'users.index', 'uses' => 'App\Http\Controllers\Api\V1\UserController@index']);

    app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('users.show');
    app('Dingo\Api\Routing\UrlGenerator')->version('v1')->route('users.index');
});

User Controller

class UserController extends Controller
{
    public function index()
    {
        return User::all();
    }

    public function show($id)
    {
        return User::where("id",$id)->first();
    }
}

How can I fix this? Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0