2018-01-29 03:19:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
/**
|
2018-03-17 13:18:03 +08:00
|
|
|
* The Award model
|
|
|
|
* @property mixed id
|
|
|
|
* @property mixed ref_class
|
|
|
|
* @property mixed|null ref_class_id
|
2018-01-29 03:19:35 +08:00
|
|
|
* @package Award\Models
|
|
|
|
*/
|
|
|
|
class Award extends BaseModel
|
|
|
|
{
|
|
|
|
public $table = 'awards';
|
|
|
|
|
|
|
|
public $fillable = [
|
|
|
|
'title',
|
|
|
|
'description',
|
2018-03-17 13:18:03 +08:00
|
|
|
'image_url',
|
|
|
|
'ref_class',
|
|
|
|
'ref_class_id',
|
2018-01-29 03:19:35 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
public static $rules = [
|
2018-03-17 13:18:03 +08:00
|
|
|
'title' => 'required',
|
|
|
|
'description' => 'nullable',
|
|
|
|
'image_url' => 'nullable',
|
2018-01-29 03:19:35 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2018-03-17 13:18:03 +08:00
|
|
|
* Get the referring object
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
2018-03-17 13:18:03 +08:00
|
|
|
public function getReference()
|
|
|
|
{
|
|
|
|
if (!$this->ref_class) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return new $this->ref_class;
|
|
|
|
# return $klass;
|
|
|
|
# return $klass->find($this->ref_class_id);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return null;
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
2018-03-17 13:18:03 +08:00
|
|
|
}
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|