12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Models\Course;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Database\Eloquent\Model;
- use DateTimeInterface;
- use Carbon\Carbon;
- class Course extends Model
- {
- use SoftDeletes;
- protected $connection = 'mysql_c';
- protected $table='course';
- protected $guarded=[];
- protected $appends = ['create_at_humans'];
- public static $courseLevel = [
- '1' =>[1],
- '2' =>[2],
- '3' =>[3],
- '4' =>[1,2],
- '5' =>[1,3],
- '6' =>[2,3],
- '7' =>[1,2,3],
- ];
- public static $levelCourse = [
- '1' =>[1,4,5,7],
- '2' =>[2,4,6,7],
- '3' =>[3,5,6,7],
- ];
- public function getImgAttribute($value)
- {
- return json_decode($value,'true');
- }
- public function getAudioAttribute($value)
- {
- return json_decode($value,'true');
- }
- public function getVideoAttribute($value)
- {
- return json_decode($value,'true');
- }
- protected function serializeDate(DateTimeInterface $date): string
- {
- return $date->format('Y-m-d H:i:s');
- }
- public function getCreateAtHumansAttribute($key)//此处的Pic与追加字段'pic' 相对应
- {
- return Carbon::createFromFormat('Y-m-d H:i:s', $this->attributes['created_at'])->diffForHumans();
- }
- // public function getCreatedAtAttribute($value){
- // return Carbon::createFromFormat('Y-m-d H:i:s', $value)->diffForHumans();
- // }
- public static function setField()
- {
- return self::query()->select('id',
- 'title',
- 'is_share',
- 'cate',
- 'perface',
- 'img',
- 'video',
- 'audio',
- 'c_id',
- 'avatar',
- 'author',
- 'permission',
- 'is_top',
- 'top_at',
- 'state',
- 'collection',
- 'share',
- 'comms',
- 'created_at',
- 'updated_at');
- }
- }
|