Student.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Models;
  3. use Carbon\Carbon;
  4. use function foo\func;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Student extends Model
  7. {
  8. protected $table = 'students';
  9. protected $guarded = [];
  10. public $marry_list;
  11. public function __construct(array $attributes = [])
  12. {
  13. parent::__construct($attributes);
  14. $this->marry_list = collect([
  15. ['key' => 1, 'value' => 1, 'show_value' => '未婚'],
  16. ['key' => 2, 'value' => 2, 'show_value' => '已婚'],
  17. // ['key' => 3, 'value' => 3, 'show_value' => '离婚'],
  18. ]);
  19. }
  20. public function getMarryList()
  21. {
  22. return $this->marry_list;
  23. }
  24. public function getMarry($key = null)
  25. {
  26. $key = empty($key) ? $this['marry'] : 1;
  27. $item = $this->marry_list->where('key', $key)->first();
  28. return empty($item) ? '未婚' : $item['show_value'];
  29. }
  30. public function course()
  31. {
  32. return $this->belongsTo('App\Models\Course');
  33. }
  34. public function getCheckCardDates()
  35. {
  36. return CheckCard::where('student_id', $this['id'])->whereNotNull('begin_date_time')->whereNotNull('end_date_time')->get()->pluck('begin_date_time')->map(function ($item) {
  37. return substr($item, 0, 10);
  38. })->unique();
  39. }
  40. public function getStudentCourse()
  41. {
  42. return StudentCourse::where('student_id', $this['id'])->first();
  43. }
  44. }