54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\QrCode\Models;
|
|
|
|
use App\Domains\Link\Models\Link;
|
|
use App\Domains\Workspace\Models\Workspace;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
|
|
class QrCode extends Model
|
|
{
|
|
/** @use HasFactory<Factory<static>> */
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'payload' => 'array',
|
|
'style' => 'array',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
if (empty($model->ulid)) {
|
|
$model->ulid = (string) Str::ulid();
|
|
}
|
|
});
|
|
}
|
|
|
|
/** @return BelongsTo<Workspace, $this> */
|
|
public function workspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Workspace::class);
|
|
}
|
|
|
|
/** @return BelongsTo<Link, $this> */
|
|
public function link(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Link::class);
|
|
}
|
|
|
|
/** @return BelongsTo<User, $this> */
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
}
|