You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticleReaction where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticleReaction first($columns = ['*'])
|
||||
*/
|
||||
class WebsiteArticleReaction extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'user_id', 'article_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $hidden = [
|
||||
'user_id',
|
||||
'article_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return static|null
|
||||
*/
|
||||
public static function getReaction(int $articleId, int $userId, string $reaction): ?self
|
||||
{
|
||||
/** @var static|null $reaction */
|
||||
$reaction = self::where('user_id', $userId)
|
||||
->where('article_id', $articleId)
|
||||
->where('reaction', $reaction)
|
||||
->first();
|
||||
|
||||
return $reaction;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->user_id = auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user