servermgrv2/app/Models/LoggerModel.php
2023-07-17 21:09:49 +09:00

49 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Entities\LoggerEntity;
class LoggerModel extends CommonModel
{
protected $table = 'logger';
// protected $primaryKey = 'uid';
// protected $useAutoIncrement = true;
protected $allowedFields = ['user_uid', 'title', 'content', 'status', 'created_at'];
protected $validationRules = [
'uid' => 'if_exist|numeric',
'user_uid' => 'if_exist|numeric',
'title' => 'if_exist|string',
'content' => 'if_exist|string',
'status' => 'if_exist|in_list[use,unuse]',
'updated_at' => 'if_exist|valid_date',
'created_at' => 'if_exist|valid_date',
];
public function getEntityByField($field, $value): ?LoggerEntity
{
return $this->asObject(LoggerEntity::class)->where($field, $value)->first();
}
public function getEntity(int $uid): ?LoggerEntity
{
return $this->getEntityByField($this->primaryKey, $uid);
}
public function create(array $datas): LoggerEntity
{
$datas['user_uid'] = session()->get('uid');
return $this->create_CommonTrait(new LoggerEntity($datas), $datas);
}
public function modify(LoggerEntity $entity, array $datas): LoggerEntity
{
return $this->modify_CommonTrait($entity, $datas);
}
//Index관련
public function setIndexWordFilter(string $word)
{
parent::setIndexWordFilter($word);
$this->orLike('title', $word, 'both');
$this->orLike('content', $word, 'both'); //befor , after , both
}
}