PHP code example of mphpmaster / laravel-model-translation-helpers

1. Go to this page and download the library: Download mphpmaster/laravel-model-translation-helpers 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/ */

    

mphpmaster / laravel-model-translation-helpers example snippets


use \MPhpMaster\LaravelModelTranslationHelpers\Traits\TModelTranslation;

public static function getTranslationKey(): ?string
{
    return str_singular(snake_case((new static)->getTable()));
}



return [
    'singular' => 'User',
    'plural' => 'Users',
    'fields' => [
        'id' => 'ID',
        'email' => 'Email',
        'password' => 'Password',
    ],
    'hi_name' => 'Hi, {name}',
];


// Basic usage
\App\Models\User::trans('singular'); // User
\App\Models\User::trans('plural'); // Users

// fields:
\App\Models\User::trans('fields.email'); // Email
// or
\App\Models\User::trans('email'); // Email

// Advanced Usage:
\App\Models\User::trans('hi_name', [ 'name' => 'mPhpMaster' ], 'en', 'Please Login!'); // Hi, mPhpMaster
shell
touch lang/en/models/user.php