chinleung/laravel-multilingual-routes

How to add parameter my route?

dmazlum opened this issue · 2 comments

Can I add parameters multilingual URL. When I attach a parameter I get 404 error.

Route::multilingual('clinic-detail/{slug}', 'ClinicsController@details')->name('clinics.details');

Hi @dmazlum,

Which version of the package are you using? Can you also add the output of your php artisan route:list?

I've just tried the following:

Route::multilingual('clinic-detail/{slug}')->name('clinics.details');

And I get the following output in my php artisan route:list:

+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+
| Domain | Method   | URI                     | Name               | Action                            | Middleware   |
+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+
|        | GET|HEAD | clinic-detail/{slug}    | en.clinics.details | Illuminate\Routing\ViewController | web          |
|        | GET|HEAD | fr/clinic-detail/{slug} | fr.clinics.details | Illuminate\Routing\ViewController | web          |
+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+

I would recommend moving the key into the translation file. So what you could do is add the following to your resources/lang/en/routes.php:

<?php

return [
    'clinic-detail' => 'clinic-detail/{slug}',
];

And then you would register the route like this:

Route::multilingual('clinic-detail', 'ClinicsController@details')->name('clinics.details');

Hi @dmazlum,

Which version of the package are you using? Can you also add the output of your php artisan route:list?

I've just tried the following:

Route::multilingual('clinic-detail/{slug}')->name('clinics.details');

And I get the following output in my php artisan route:list:

+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+
| Domain | Method   | URI                     | Name               | Action                            | Middleware   |
+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+
|        | GET|HEAD | clinic-detail/{slug}    | en.clinics.details | Illuminate\Routing\ViewController | web          |
|        | GET|HEAD | fr/clinic-detail/{slug} | fr.clinics.details | Illuminate\Routing\ViewController | web          |
+--------+----------+-------------------------+--------------------+-----------------------------------+--------------+

I would recommend moving the key into the translation file. So what you could do is add the following to your resources/lang/en/routes.php:

<?php

return [
    'clinic-detail' => 'clinic-detail/{slug}',
];

And then you would register the route like this:

Route::multilingual('clinic-detail', 'ClinicsController@details')->name('clinics.details');

Hello @chinleung , Your code is working now. Thanks.