chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
401 stars 25 forks source link

How to add parameter my route? #42

Closed dmazlum closed 4 years ago

dmazlum commented 4 years ago

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');
chinleung commented 4 years ago

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');
dmazlum commented 4 years ago

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.