mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-22 17:32:14 +00:00
cleaning
This commit is contained in:
71
app/Models/Language.php
Normal file
71
app/Models/Language.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\LanguageString;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Language extends Model
|
||||
{
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public $incrementing = false ;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($language) {
|
||||
$language->id = Str::uuid();
|
||||
});
|
||||
|
||||
static::deleting(function ($language) {
|
||||
DB::table('language_strings')
|
||||
->where('lang', $language->locale)
|
||||
->delete();
|
||||
|
||||
Cache::forget('language_strings-' . $language->locale );
|
||||
});
|
||||
|
||||
static::updated(function($language) {
|
||||
Cache::forget('language_strings-' . $language->locale );
|
||||
|
||||
});
|
||||
|
||||
static::created(function ($language) {
|
||||
|
||||
$license = get_setting('license') === 'Extended' ? 'extended' : 'regular';
|
||||
|
||||
$language_strings = collect(config('language_strings.' . $license));
|
||||
|
||||
$strings = $language_strings->map(function ($value , $key) use($language) {
|
||||
|
||||
return [
|
||||
'key' => $key,
|
||||
'lang' => $language->locale,
|
||||
'value' => $value
|
||||
];
|
||||
|
||||
})->toArray();
|
||||
|
||||
DB::table('language_strings')
|
||||
->insert($strings);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public function languageStrings()
|
||||
{
|
||||
return $this->hasMany('App\LanguageString', 'lang', 'locale');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user