2023-08-23 18:19:50 +06:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Manga extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
2023-08-30 21:15:58 +06:30
|
|
|
|
|
|
|
protected $fillable = ['title', 'slug', 'summary', 'excerpt', 'cover', 'author_id'];
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class, 'author_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function chapters()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Chapter::class);
|
|
|
|
}
|
2023-09-24 22:24:08 +06:30
|
|
|
|
|
|
|
//latest and oldest chapter
|
|
|
|
// public function latestChap()
|
|
|
|
// {
|
|
|
|
// return $this->chapters()->one()->latestOfMany();
|
|
|
|
// }
|
2023-12-12 15:15:38 +06:30
|
|
|
|
2023-09-24 22:24:08 +06:30
|
|
|
public function lastChap()
|
|
|
|
{
|
|
|
|
return $this->chapters()->one()->ofMany('chapter_no', 'max');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function firstChap()
|
|
|
|
{
|
|
|
|
return $this->chapters()->one()->ofMany('chapter_no', 'min');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function genres()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Genre::class);
|
|
|
|
}
|
2023-08-23 18:19:50 +06:30
|
|
|
}
|