MentalityDrill.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. class MentalityDrill extends SoftBaseModel
  5. {
  6. protected $casts = ['video'=>'array','comment_tag'=>'array'];
  7. public function getPicAttribute()
  8. {
  9. return isset($this->attributes['pic']) ? config('console.pic_path').$this->attributes['pic'] : NULL;
  10. }
  11. public function category(){
  12. return $this->belongsTo(MentalityDrillCategory::class, 'category_id', 'id');
  13. }
  14. public function extend(){
  15. return $this->hasMany(MentalityDrillExtend::class, 'drill_id', 'id');
  16. }
  17. public function subject(){
  18. return $this->hasMany(MentalityDrillsSubject::class, 'mentality_drills_id', 'id');
  19. }
  20. public function leaveMessage(){
  21. return $this->hasMany(SpecialistInfoLeaveMessage::class, 'mentality_drills_id', 'id')
  22. ->with(
  23. ["user"=>function($with){
  24. $with->select(['id','wx_nickname','wx_headimgurl','third_up_nickname','third_up_headimg']);
  25. }
  26. ]
  27. );
  28. }
  29. protected static function booted()
  30. {
  31. static::creating(function ($model) {
  32. if (empty($model->two_category_id)){
  33. $model->two_category_id = 0;
  34. }
  35. });
  36. }
  37. }