ArticleEvent.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php namespace App\Models;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Carbon;
  5. /**
  6. * 用户操作模型
  7. *
  8. */
  9. class ArticleEvent extends Model
  10. {
  11. use HasFactory;
  12. // 与模型关联的表名
  13. protected $table = 'article_event';
  14. // 是否主动维护时间戳
  15. public $timestamps = false;
  16. // 定义时间戳字段名
  17. // const CREATED_AT = 'insert_time';
  18. // const UPDATED_AT = 'update_time';
  19. /**
  20. * 添加数据
  21. *
  22. */
  23. public function add($data)
  24. {
  25. // 时间
  26. $data['insert_time'] = time();
  27. $data['update_time'] = time();
  28. // 写入数据表
  29. $id = $this->query()->insertGetId($data);
  30. // 返回结果
  31. return $id;
  32. }
  33. /**
  34. * 添加数据
  35. *
  36. */
  37. public function edit($id,$data)
  38. {
  39. // 更新时间
  40. $data['update_time'] = time();
  41. // 写入数据表
  42. $result = $this->query()->where(['id'=>$id])->update($data);
  43. // 返回结果
  44. return $result;
  45. }
  46. }