Init
This commit is contained in:
72
app/Models/Hentai.php
Normal file
72
app/Models/Hentai.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||
use Spatie\Sitemap\Tags\Url;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Conner\Tagging\Taggable;
|
||||
use Laravelista\Comments\Commentable;
|
||||
|
||||
class Hentai extends Model implements Sitemapable
|
||||
{
|
||||
use Commentable, Taggable;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'slug',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function episodes()
|
||||
{
|
||||
return $this->hasMany(Episode::class, 'hentai_id');
|
||||
}
|
||||
|
||||
public function torrents()
|
||||
{
|
||||
return $this->hasMany(Torrents::class, 'hentai_id');
|
||||
}
|
||||
|
||||
public function title(): String
|
||||
{
|
||||
return $this->episodes->first()->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has a Gallery.
|
||||
*/
|
||||
public function gallery()
|
||||
{
|
||||
return $this->hasMany(Gallery::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if hentai contains loli / shota tag
|
||||
*/
|
||||
public function isLoliOrShota(): bool
|
||||
{
|
||||
$problematicTags = ['Loli', 'Shota'];
|
||||
|
||||
return Cache::remember(
|
||||
"episode:{$this->id}:has_problematic_tags",
|
||||
now()->addMinutes(1440),
|
||||
fn () => $this->episodes[0]->tags->pluck('name')->intersect($problematicTags)->isNotEmpty()
|
||||
);
|
||||
}
|
||||
|
||||
public function toSitemapTag(): Url | string | array
|
||||
{
|
||||
return Url::create(route('hentai.index', $this->slug))
|
||||
->setLastModificationDate(Carbon::create($this->created_at));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user