WowPress-Tailwind/theme/wowpress/Models/CharacterListItem.php

35 lines
732 B
PHP
Raw Normal View History

2024-08-07 22:34:54 +02:00
<?php
namespace WoWPress\Models;
use LogicException;
use Wenprise\Eloquent\Model;
class CharacterListItem extends Model{
protected $table = "wowpress_charlists_item";
public $timestamps = false;
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public function list(){
$this->belongsTo(CharacterList::class,'list_id');
}
public function character(){
$this->belongsTo(Character::class,'character_id');
}
public static function deleteOrphans(){
$items = static::all();
foreach($items as $item){
try{
$item->list;
}catch(LogicException $e){
$item->delete();
}
}
}
}