Course.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Models\Course;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. use Illuminate\Database\Eloquent\Model;
  5. use DateTimeInterface;
  6. use Carbon\Carbon;
  7. class Course extends Model
  8. {
  9. use SoftDeletes;
  10. protected $connection = 'mysql_c';
  11. protected $table='course';
  12. protected $guarded=[];
  13. protected $appends = ['create_at_humans'];
  14. public static $courseLevel = [
  15. '1' =>[1],
  16. '2' =>[2],
  17. '3' =>[3],
  18. '4' =>[1,2],
  19. '5' =>[1,3],
  20. '6' =>[2,3],
  21. '7' =>[1,2,3],
  22. ];
  23. public static $levelCourse = [
  24. '1' =>[1,4,5,7],
  25. '2' =>[2,4,6,7],
  26. '3' =>[3,5,6,7],
  27. ];
  28. public function getImgAttribute($value)
  29. {
  30. return json_decode($value,'true');
  31. }
  32. public function getAudioAttribute($value)
  33. {
  34. return json_decode($value,'true');
  35. }
  36. public function getVideoAttribute($value)
  37. {
  38. return json_decode($value,'true');
  39. }
  40. protected function serializeDate(DateTimeInterface $date): string
  41. {
  42. return $date->format('Y-m-d H:i:s');
  43. }
  44. public function getCreateAtHumansAttribute($key)//此处的Pic与追加字段'pic' 相对应
  45. {
  46. return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans();
  47. }
  48. // public function getCreatedAtAttribute($value){
  49. // return Carbon::createFromFormat('Y-m-d H:i:s', $value)->diffForHumans();
  50. // }
  51. public static function setField()
  52. {
  53. return self::query()->select('id',
  54. 'title',
  55. 'is_share',
  56. 'cate',
  57. 'perface',
  58. 'img',
  59. 'video',
  60. 'audio',
  61. 'c_id',
  62. 'avatar',
  63. 'author',
  64. 'permission',
  65. 'is_top',
  66. 'top_at',
  67. 'state',
  68. 'collection',
  69. 'share',
  70. 'comms',
  71. 'created_at',
  72. 'updated_at');
  73. }
  74. }