You've already forked Epicnabbo-Catalogus-Updated-Daily
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Articles;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class WebsiteArticleReaction extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $hidden = [
|
|
'user_id',
|
|
'article_id',
|
|
];
|
|
|
|
public static function getReaction(int $articleId, int $userId, string $reaction): ?self
|
|
{
|
|
return self::where('user_id', $userId)
|
|
->where('article_id', $articleId)
|
|
->where('reaction', $reaction)
|
|
->first();
|
|
}
|
|
|
|
#[\Override]
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function ($model): void {
|
|
$model->user_id = auth()->id();
|
|
});
|
|
}
|
|
|
|
public function article(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|