PHP code example of riseno / localizable

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

    

riseno / localizable example snippets


Riseno\Localizable\LocalizableServiceProvider::class,

Schema::create('user_localizations', function(Blueprint $table)
{
	$table->increments('id');
	$table->unsignedInteger('user_id');
	$table->string('locale');
	$table->boolean('default')->default(false);
	$table->string('name')->nullable();
	$table->timestamps();
	$table->foreign('user_id')->references('id')->on('users');
});

use Riseno\Localizable\LocalizableTrait;

class User extends Authenticatable
{
    use LocalizableTrait;

protected $localizeModel  = UserLocalizations::class;
protected $localizeFields = ['name'];

public function localizations()
{
    return $this->hasMany(UserLocalizations::class, 'user_id', 'id');
}

$user->localize('en_US');
// or access value directly
$user->localize('en_US')->name;

$user->saveLocalize('en_US', ['name' => 'Riseno']);
bash
php artisan riseno:localizable:generate user
bash
php artisan migrate