Student.php 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Student extends Model
  5. {
  6. protected $table = 'students';
  7. protected $guarded = [];
  8. public $marry_list;
  9. public function __construct(array $attributes = [])
  10. {
  11. parent::__construct($attributes);
  12. $this->marry_list = collect([
  13. ['key' => 1, 'value' => 1, 'show_value' => '未婚'],
  14. ['key' => 2, 'value' => 2, 'show_value' => '已婚'],
  15. // ['key' => 3, 'value' => 3, 'show_value' => '离婚'],
  16. ]);
  17. }
  18. public function getMarryList()
  19. {
  20. return $this->marry_list;
  21. }
  22. public function getMarry($key = null)
  23. {
  24. $key = empty($key) ? $this['marry'] : 1;
  25. $item = $this->marry_list->where('key', $key)->first();
  26. return empty($item) ? '未婚' : $item['show_value'];
  27. }
  28. public function course()
  29. {
  30. return $this->belongsTo('App\Models\Course');
  31. }
  32. }