44 lines
992 B
PHP
44 lines
992 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\DynamicFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
|
|
|
class Dynamic extends Model
|
|
{
|
|
/** @use HasFactory<DynamicFactory> */
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'rules',
|
|
];
|
|
|
|
public function participants(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class, 'participants');
|
|
}
|
|
|
|
public function ledgers(): HasMany
|
|
{
|
|
return $this->hasMany(Ledger::class);
|
|
}
|
|
|
|
public function chat(): MorphOne
|
|
{
|
|
return $this->morphOne(Chat::class, 'chatable');
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function (Dynamic $dynamic) {
|
|
$dynamic->chat()->create([]);
|
|
});
|
|
}
|
|
}
|