Instead of creating multiple tables and handling translations via a different table, this package uses a single table and a JSON column to store the translations.

Installation
Installation guide for this package is really simple and consists only of two steps:
Require the package via composer:
composer require spatie/laravel-translatable
And for the models you want to translate add the Spatie\Translatable\HasTranslations trait with $translatable property:
Model
use Spatie\Translatable\HasTranslations; class Post extends Model{ use HasTranslations; public $translatable = ['title'];}
That is it! Now if you set up the database column title to be a JSON column (or TEXT in unsupported databases), you can start using the package.
Usage
Here's a quick example of how we used this package:...
I want add thing if want add more than languages so you need add tab like this ex: @foreach (config('locales.languages') as $key => $val)
Meta-Bereich
namespace App\Translators;
use GuzzleHttp\Client; use Illuminate\Support\Facades\Cache;
class DeepLTranslator { public function translate($text, $target_lang = 'de') { // dd($text); if (\is_array($text)){ $text = $text['de']; } // Check if the translation is already in the cache $cachedTranslation = Cache::get("translation_{$text}_{$target_lang}"); if ($cachedTranslation) { return $cachedTranslation; }
try{ $response = $client->post('https://api.deepl.com/v2/translate', [ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => 'name' ], 'form_params' => [ 'auth_key' => env('DEEPL_API_KEY'), 'text' => $text, 'target_lang' => $target_lang ] ]); } catch (\Exception $e) { return $e->getMessage(); }
}