123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Student extends Model
- {
- protected $table = 'students';
- protected $guarded = [];
- public $marry_list;
- public function __construct(array $attributes = [])
- {
- parent::__construct($attributes);
- $this->marry_list = collect([
- ['key' => 1, 'value' => 1, 'show_value' => '未婚'],
- ['key' => 2, 'value' => 2, 'show_value' => '已婚'],
- // ['key' => 3, 'value' => 3, 'show_value' => '离婚'],
- ]);
- }
- public function getMarryList()
- {
- return $this->marry_list;
- }
- public function getMarry($key = null)
- {
- $key = empty($key) ? $this['marry'] : 1;
- $item = $this->marry_list->where('key', $key)->first();
- return empty($item) ? '未婚' : $item['show_value'];
- }
- public function course()
- {
- return $this->belongsTo('App\Models\Course');
- }
- }
|