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

35 lines
1.0 KiB
PHP
Raw Normal View History

2024-08-07 22:34:54 +02:00
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
class CharacterList extends Model{
protected $table = "wowpress_charlists";
public $timestamps = false;
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public function characters(){
return $this->belongsToMany(Character::class,'wowpress_charlists_item','character_id','list_id')->orderBy('character_id')->orderByPivot('date')->withPivot('comment','date','ID');
}
public function addItem(Character $char, $comment = null, $date = null, $multiplier = 1){
$this->characters()->attach($char->ID,[
'comment' => $comment,
'date' => $date?:date('Y-m-d'),
'count_multiplier' => $multiplier
]);
if($this->notify){
if($char->user){
Notification::addNotification($char->user->ID,'Neuer Eintrag in Liste: '.$this->list_name);
}
}
}
public function removeItem($id){
$this->characters()->wherePivot('id',$id)->first()->detach();
}
}