Missing required parameter for [Route: users.show] [URI: api/users/{id}] [Missing parameter: id]
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
| 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.
Contributor guide
Assessment
This issue has not been assessed yet.