2024-10-18 14:28:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Models\Traits\CanEncryptField;
|
|
|
|
use Database\Factories\IconFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* App\Models\Icon
|
|
|
|
*
|
|
|
|
* @property string $name
|
|
|
|
* @property string|null $content
|
|
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
|
|
* @property-read \App\Models\TwoFAccount|null $twofaccount
|
2024-11-09 10:18:45 +01:00
|
|
|
*
|
2024-10-18 14:28:45 +02:00
|
|
|
* @method static \Database\Factories\IconFactory factory($count = null, $state = [])
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon whereContent($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Icon whereUpdatedAt($value)
|
|
|
|
*/
|
|
|
|
class Icon extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @use HasFactory<IconFactory>
|
|
|
|
*/
|
2024-11-09 10:18:45 +01:00
|
|
|
use CanEncryptField, HasFactory;
|
2024-10-18 14:28:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The primary key for the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $primaryKey = 'name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The "type" of the primary key ID.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $keyType = 'string';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the IDs are auto-incrementing.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $incrementing = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the twofaccount that owns the icon.
|
2024-11-09 10:18:45 +01:00
|
|
|
*
|
2024-11-23 14:29:31 +01:00
|
|
|
* @return BelongsTo<\App\Models\TwoFAccount, $this>
|
2024-10-18 14:28:45 +02:00
|
|
|
*/
|
|
|
|
public function twofaccount() : BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(TwoFAccount::class, 'name', 'icon');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The model's attributes.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $attributes = [];
|
2024-11-09 10:18:45 +01:00
|
|
|
|
2024-10-18 14:28:45 +02:00
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
protected $hidden = ['created_at', 'updated_at'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
protected $fillable = ['name'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get content attribute
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getContentAttribute($value)
|
|
|
|
{
|
|
|
|
return $this->decryptOrReturn(base64_decode($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set content attribute
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setContentAttribute($value)
|
|
|
|
{
|
|
|
|
// Encrypt if needed
|
|
|
|
$this->attributes['content'] = $this->encryptOrReturn(base64_encode($value));
|
|
|
|
}
|
|
|
|
}
|