0
votes

I'm trying to generate a url with parameter using laravel route helper,

route('frontend.admin.categories.edit', $catRequest->id)

but this is the generated url

http://localhost:8000/admin/categories/edit?1

I need a URL like this

http://localhost:8000/admin/categories/edit/1

And this is my route

 Route::get('admin/categories/edit/{id}', 'CategoryController@edit')
        ->name('admin.categories.edit');

What is the issue here?

3

3 Answers

1
votes

You can specify the parameter(s) you are replacing by passing an associative array instead of a variable.

Change,

route('frontend.admin.categories.edit', $catRequest->id)

To

route('frontend.admin.categories.edit', [
    'id' => $catRequest->id
]);

Edit #1

You are calling the wrong route, you named your route as admin.categories.edit in the definition yet you are calling frontend.admin.categories.edit within the helper function which is not the originally defined route. So your code should be:

route('admin.categories.edit', [
    'id' => $catRequest->id
]);

Reading Material

Named Routes

0
votes

You need to use an array for your params :

route('frontend.admin.categories.edit', ['id' => $catRequest->id])

If not, all params will be used as $_GET params.

0
votes

Try to view your route list using php artisan route:list. If you found your route in list with correct Uri then see that you are not again specify that route with same Uri or same alias name in your route file.

Hope this helps :)