Home > PHP Framework > Laravel > body text

Laravel registers multi-language routing

藏色散人
Release: 2019-10-02 17:45:18
forward
2942 people have browsed it

Laravel registers multi-language routing

Laravel Multilingual Routes is an extension package of Chin Leung to register multilingual routes for your application. Instead of the following routing settings:

Route::get('/', 'ShowHomeController')->name('en.home');
Route::get('/fr', 'ShowHomeController')->name('fr.home');
Copy after login

You can accomplish the same thing with this extension package:

Route::multilingual('/', 'ShowHomeController')->name('home');
Copy after login

This package also comes with a middleware that automatically detects and changes the application's based on the request. regional settings.

protected $middlewareGroups = [
    'web' => [
        \ChinLeung\LaravelMultilingualRoutes\DetectRequestLocale::class,
        // ...
    ]
];
Copy after login

You can configure the required language through the chinleung/laravel-locales package:

// config/locales.php
'supported' => [
    'en',
    'es',
    'fr',
],
Copy after login

Please be sure to check the README of the package, It contains examples of everything a multilingual package can do. You can learn more about this package at chinleung/laravel-multilingual-routes, get complete installation instructions, and view the source code on GitHub.

For more Laravel related technical articles, please visit the Laravel Framework Getting Started Tutorial column to learn!

The above is the detailed content of Laravel registers multi-language routing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!