PHP code example of kolirt / laravel-translations

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

    

kolirt / laravel-translations example snippets




$query->withoutGlobalScope('translatable');



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Kolirt\Translations\Traits\Translatable;

class Tag extends Model
{

    use Translatable;

    protected $fillable = ['name', 'slug', 'description', 'sort_order', 'active'];

    protected $translatable = ['name', 'slug', 'description' => 'text'];
    
}



$tag = Tag::first();
$tag->name;

// OR

$tag = Tag::first();
$tag->translation('name');



$tag = Tag::first();
$tag->translations('name');



$tag = Tag::first();
$tag->name = 1;
$tag->save();



$tag = Tag::first();
$tag->update([
    'name' => [
        'uk' => 'uk label',
        'en' => 'en label'
    ]
]);



$request->validate([
    'name.*' => [
        'unique_loc:table,type,name,id' // id not ' => [
            'uk' => 'uk label'
            'en' => 'en label'
        ]
*/



Tag::translatable()->first();

$ php artisan translations:install