generated from Flycro/laravel-nuxt
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Events\BookRecommendation\BookRecommendationCreated;
|
|
use App\Events\BookRecommendation\BookRecommendationDeleted;
|
|
use App\Events\BookRecommendation\BookRecommendationUpdated;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class BookRecommendation extends Model
|
|
{
|
|
protected $table = 'book_recommendations';
|
|
|
|
protected $fillable = [
|
|
'book_name',
|
|
'author',
|
|
'description',
|
|
'isbn',
|
|
'pages',
|
|
'recommended_by',
|
|
'cover_image',
|
|
'status',
|
|
'published_at',
|
|
];
|
|
|
|
protected static function booted() :void
|
|
{
|
|
static::created(static function ($bookRecommendation) {
|
|
broadcast(new BookRecommendationCreated($bookRecommendation))->toOthers();
|
|
});
|
|
|
|
static::updated(static function ($task) {
|
|
broadcast(new BookRecommendationUpdated($task))->toOthers();
|
|
});
|
|
|
|
static::deleting(static function ($task) {
|
|
broadcast(new BookRecommendationDeleted($task))->toOthers();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the user that recommended the book.
|
|
*/
|
|
public function recommender(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'recommended_by');
|
|
}
|
|
|
|
public function votes(): HasMany
|
|
{
|
|
return $this->hasMany(Vote::class);
|
|
}
|
|
|
|
public function deadlines(): HasMany
|
|
{
|
|
return $this->hasMany(Deadline::class);
|
|
}
|
|
}
|