PHP code example of codanux / multi-language

1. Go to this page and download the library: Download codanux/multi-language 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/ */

    

codanux / multi-language example snippets

 php
php artisan vendor:publish --provider="Codanux\MultiLanguage\MultiLanguageServiceProvider"
 php
config/multi-language.php

'middleware' => [
    'web' => [
        \Codanux\MultiLanguage\DetectRequestLocale::class
    ]
],
 php
Route::localeResource('post', 'PostController')->names('post');
or
Route::locale('post.index', 'PostController@index');
Route::locale('post.show', 'PostController@show');
Route::locale('post.create', 'PostController@create');
Route::locale('post.create', 'PostController@store')->method('POST');
Route::locale('post.edit', 'PostController@edit');
Route::locale('post.edit', 'PostController@update')->method('PUT');
Route::locale('post.destroy', 'PostController@destroy')->method('DELETE');


Route::locale('dashboard', function () {
    return view('dashboard');
})
->name('home');

Route::group(['localePrefix' => 'admin.prefix'], function (){

    Route::locale('admin.dashboard', function () {
        return view('admin.dashboard');
    });

});
 php
public function index()
{
    // locale scope
    $posts = (new Post())->newQuery()->locale()->get();
}

public function store(Request $request)
{
    $post = Post::create([
       'name' => 'Post en',
       'locale' => 'en',
   ]);

    Post::create([
       'name' => 'Post tr',
       'locale' => 'tr',
       'locale_slug' => 'post-1',
       'translation_of' => $post->translation_of
    ]);
    
    Post::localeSlug('post-1', 'tr')->first(); // Post tr
    
    Post::localeSlug('post-1', 'en')->first(); // Post en
}

public function show(Post $post)
{
    return view('post.show', compact('post'));
}
 php
post.index
    <x-links component="jet-nav-link"></x-links>

post.show
    <x-links :translations=['post' => $post]></x-links>
    
    //category/{category}/posts/{post}

    // route model translations ['category' => $category, 'post => $post]
 php
1. config/multi-language.php

'fortify' => [
    'routes' => true,
],

'jetstream' => [
    'routes' => true,
]

2. Default Router İgnore

class FortifyServiceProvider extends ServiceProvider
{
    public function register()
    {
        Fortify::ignoreRoutes();
    }
}

class JetstreamServiceProvider extends ServiceProvider
{
   public function register()
   {
       Jetstream::ignoreRoutes();
   }
}