dimanche 15 novembre 2020

Laravel Multi language site database

Laravel e-commerce site.

Arabic and English languages website. I have tried to develop Multilanguage site with laraval. But I am confused at the below point.

Suppose I have Category table with title field. I want to insert title field in the two language. So i have created migration for title_en and title_ar.

<?php
namespace App;
use App\Traits\MultiLanguage;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
    use MultiLanguage;
    protected $fillable = [
        'title_en', 'title_ar',
    ];
    /**
      * This array will have the attributes which you want it to support multi languages
    */
    protected $multi_lang = [
        'title',
    ];
}

Here is multi language traits:

<?php

namespace App\Traits;
use Illuminate\Support\Facades\App;
trait MultiLanguage
{

    public function __get($key)
    {
        if (isset($this->multi_lang) && in_array($key, $this->multi_lang)) {
            $key = $key . '_' . App::getLocale();
         }
        return parent::__get($key);
    }
}

But what to do when there are many table fields also how to insert records. If You have any solution. Please guide me. how can it possible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire