Project.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Models;
  3. use App\Casts\Htmlspecialchar;
  4. use App\Casts\Json;
  5. use DateTimeInterface;
  6. use Illuminate\Database\Eloquent\Factories\HasFactory;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. class Project extends Model
  10. {
  11. use HasFactory,SoftDeletes;
  12. protected $table = 'js_project';
  13. // protected array $dates = ['delete_time'];
  14. const CREATED_AT = 'create_time';
  15. const UPDATED_AT = 'update_time';
  16. // 自定义软删除字段 默认 deleted_at
  17. const DELETED_AT = 'delete_time';
  18. protected $dateFormat = 'U';
  19. protected $fillable = ['name','icon','banner','content','price','order_price','minute','brief','is_show'];
  20. protected $hidden = [
  21. //
  22. ];
  23. protected $casts = [
  24. // 'create_time' => 'datetime',
  25. // 'password' => 'hashed',
  26. 'banner' => Json::class,
  27. 'content' => Htmlspecialchar::class
  28. ];
  29. protected function serializeDate(DateTimeInterface $date): string
  30. {
  31. return $date->format('Y-m-d H:i:s');
  32. }
  33. public function category()
  34. {
  35. return $this->hasMany(ProjectCategory::class,'project_id','id');
  36. }
  37. }