PHP code example of chinleung / laravel-multilingual-routes

1. Go to this page and download the library: Download chinleung/laravel-multilingual-routes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chinleung / laravel-multilingual-routes example snippets


localized_route('test'); // Returns the url of the current application locale
localized_route('test', [], 'fr'); // Returns https://app.test/fr/teste
localized_route('test', [], 'en'); // Returns https://app.test/test

current_route(); // Returns the current request's route
current_route('fr'); // Returns the current request's route in French version
current_route('fr', route('fallback')); // Returns the fallback route if the current route is not registered in French

Route::multilingual('test', 'TestController')->name('foo');

Route::multilingual('test', 'TestController')->names([
  'en' => 'foo',
  'fr' => 'bar',
]);

Route::multilingual('test', 'TestController')->except(['fr']);

Route::multilingual('test', 'TestController')->only(['fr']);

Route::multilingual('test', 'TestController')->method('post');

// Loads test.blade.php
Route::multilingual('test');

// Loads welcome.blade.php instead of test.blade.php
Route::multilingual('test')->view('welcome');

Route::multilingual('test')->data(['name' => 'Taylor']);
Route::multilingual('test')->view('welcome', ['name' => 'Taylor']);

Route::multilingual('support');
Route::multilingual('contact')->redirect('support');

Request::localizedRouteIs('home');

URL::signedLocalizedRoute('unsubscribe', ['user' => 1]);
URL::temporarySignedLocalizedRoute('unsubscribe', now()->addMinutes(30), ['user' => 1]);
 php
protected $middlewareGroups = [
    'web' => [
        \ChinLeung\MultilingualRoutes\DetectRequestLocale::class,
        // ...
    ]
];
 bash
php artisan vendor:publish --provider="ChinLeung\MultilingualRoutes\MultilingualRoutesServiceProvider" --tag="config"
 php
Route::get('/', 'ShowHomeController')->name('en.home');
Route::get('/fr', 'ShowHomeController')->name('fr.home');
 php
Route::multilingual('/', 'ShowHomeController')->name('home');
 php
Route::multilingual('test', 'TestController');
 php


// resources/lang/fr/routes.php

return [
  'test' => 'teste'
];