Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id] #1784

Open
hsariaslan opened this issue Aug 21, 2021 · 0 comments

Comments

@hsariaslan
Copy link

| 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant