MrAli
2 weeks ago
309
19
Laravel

Route pattern "/{username}/{{username}}" cannot reference variable name "username" more than once.

Posted 2 weeks ago by MrAli

Hi

I am building web app. where url need to be like:

site.com/{username}/{id}

Route::get('/', '[email protected]');

Auth::routes();
Route::resource('post', 'PsotsController');

Route::get('/profile', '[email protected]')->name('home');

so i did

Route::resource('{username}', 'PostsController');

and i get the error : Route pattern "/{username}/{{username}}" .

λ php artisan route:list
.

 {username}                   | {username}.index   | App\Http\Controllers\[email protected]
 {username}                   | {username}.store   | App\Http\Controllers\[email protected]
 {username}/create            | {username}.create  | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.update  | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.show    | App\Http\Controllers\[email protected]
 {username}/{{username}}      | {username}.destroy | App\Http\Controllers\[email protected]
 {username}/{{username}}/edit | {username}.edit    | App\Http\Controllers\[email protected]

How to delete the second {{username}} from the url pattern?

Please sign in or create an account to participate in this conversation.