52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
/**
|
|
* @property int $value_id
|
|
* @property int $translation_id
|
|
* @property string $lang_code
|
|
* @property string $lang_value
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
* @property string $deleted_at
|
|
*/
|
|
class TranslationValue extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'translation_value';
|
|
|
|
protected string $primaryKey = "value_id";
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['value_id' => 'integer', 'translation_id' => 'integer'];
|
|
|
|
public static function setValue(int $id, array $values): bool
|
|
{
|
|
foreach ($values as $value) {
|
|
$info = self::where("translation_id", $id)
|
|
->where("lang_code", $value['lang_code'])
|
|
->first();
|
|
if (empty($info)) {
|
|
$value['translation_id'] = $id;
|
|
self::add($value);
|
|
} else {
|
|
$info->lang_value = $value['lang_value'];
|
|
$info->save();
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|