2026-05-20 18:25:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-06-08 16:25:52 +02:00
|
|
|
use App\Auth\XenForoUser;
|
|
|
|
|
use App\Services\XenforoService;
|
2026-05-20 18:25:15 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-06-08 16:25:52 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-06-30 14:06:11 +02:00
|
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
|
|
|
use Spatie\Activitylog\Support\LogOptions;
|
2026-05-20 18:25:15 +02:00
|
|
|
|
2026-06-10 11:04:26 +02:00
|
|
|
/**
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $slug
|
|
|
|
|
* @property string|null $website
|
|
|
|
|
* @property int|null $user_id
|
|
|
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
|
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Entry> $entries
|
|
|
|
|
* @property-read int|null $entries_count
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author newModelQuery()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author newQuery()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author query()
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereCreatedAt($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereName($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereSlug($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereUpdatedAt($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereUserId($value)
|
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder<static>|Author whereWebsite($value)
|
|
|
|
|
* @mixin \Eloquent
|
|
|
|
|
*/
|
2026-05-20 18:25:15 +02:00
|
|
|
class Author extends Model
|
|
|
|
|
{
|
2026-06-30 14:06:11 +02:00
|
|
|
|
|
|
|
|
use LogsActivity;
|
|
|
|
|
|
2026-05-20 18:25:15 +02:00
|
|
|
protected $fillable = [
|
|
|
|
|
'name', 'slug', 'user_id', 'website'
|
|
|
|
|
];
|
2026-06-08 16:25:52 +02:00
|
|
|
|
|
|
|
|
public function entries(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Entry::class, 'entry_authors');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): ?XenForoUser
|
|
|
|
|
{
|
|
|
|
|
if( !$this->user_id )
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return app(XenforoService::class)->getXfUser($this->user_id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-30 14:06:11 +02:00
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
|
|
|
{
|
|
|
|
|
return LogOptions::defaults()
|
|
|
|
|
->useLogName('author')
|
|
|
|
|
->logAll()
|
|
|
|
|
->logOnlyDirty()
|
|
|
|
|
->dontLogEmptyChanges()
|
|
|
|
|
->setDescriptionForEvent(fn(string $eventName) => "Author {$eventName}");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 18:25:15 +02:00
|
|
|
}
|