PHP code example of marshmallow / multi-language

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

    

marshmallow / multi-language example snippets


protected $middlewareGroups = [
    'web' => [
        //...
        \Illuminate\Session\Middleware\StartSession::class,

        /**
         * Make sure you put this below the StartSession middleware
         */
        \Marshmallow\MultiLanguage\Http\Middleware\MultiLanguageMiddleware::class,
        
        //...
    ],

public function tools()
{
    return [
        new \Digitalcloud\MultilingualNova\NovaLanguageTool,
    ];
}

public function fields(Request $request)
{
	return [
		// ...
		Multilingual::make('Language'),
	]
}

use Marshmallow\MultiLanguage\Traits\TranslatableRoute;
use Spatie\Translatable\HasTranslations;

class Page extends Model
{
    use HasTranslations, TranslatableRoute;
    public $translatable = ['name', 'slug', 'layout'];
}

Route::get('locale/{locale}', function ($locale){
    Session::put('locale', $locale);
    return redirect()->back();
});

public function route ()
{
	return '/' . App::getLocale() . $this->routePrefix() . $this->slug;
}

protected function routePrefix ()
{
	return '';
}