|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SaasReady\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
9
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
10
|
|
|
use SaasReady\Database\Factories\TranslationFactory; |
|
11
|
|
|
use SaasReady\Traits\EloquentBuilderMixin; |
|
12
|
|
|
use SaasReady\Traits\HasUuid; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @property-read int $id |
|
16
|
|
|
* @property string $key |
|
17
|
|
|
* @property string $label |
|
18
|
|
|
* @property array $translations eg: ['en' => 'Seth Phat', 'vi' => 'Phat Tran'] |
|
19
|
|
|
* @property ?Carbon $created_at |
|
20
|
|
|
* @property ?Carbon $updated_at |
|
21
|
|
|
* @property ?Carbon $deleted_at |
|
22
|
|
|
* |
|
23
|
|
|
* @method static Builder|static filterByKeyword(string $keyword) |
|
24
|
|
|
* |
|
25
|
|
|
* @mixin EloquentBuilderMixin |
|
26
|
|
|
*/ |
|
27
|
|
|
class Translation extends Model |
|
28
|
|
|
{ |
|
29
|
|
|
use HasFactory; |
|
30
|
|
|
use SoftDeletes; |
|
31
|
|
|
use HasUuid; |
|
32
|
|
|
|
|
33
|
|
|
protected $table = 'translations'; |
|
34
|
|
|
|
|
35
|
|
|
protected $fillable = [ |
|
36
|
|
|
'key', |
|
37
|
|
|
'label', |
|
38
|
|
|
'translations', |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
protected $casts = [ |
|
42
|
|
|
'translations' => 'array', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
public static function findByKey(string $key, array $columns = ['*']): ?static |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
return static::where('key', $key)->first($columns); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function scopeFilterByKeyword(Builder $builder, string $keyword): Builder |
|
51
|
|
|
{ |
|
52
|
|
|
return $builder->where(function (Builder $builder) use ($keyword) { |
|
53
|
|
|
$builder->orWhere('key', 'LIKE', '%' . $keyword . '%') |
|
54
|
|
|
->orWhere('label', 'LIKE', '%' . $keyword . '%') |
|
55
|
|
|
->orWhere('translations', 'LIKE', '%' . $keyword . '%'); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @codeCoverageIgnore |
|
61
|
|
|
*/ |
|
62
|
|
|
protected static function newFactory(): TranslationFactory |
|
63
|
|
|
{ |
|
64
|
|
|
return TranslationFactory::new(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|