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
|
2018-03-18 00:35:34 +08:00
|
|
|
* @property mixed|null ref_class_params
|
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',
|
2018-03-18 00:35:34 +08:00
|
|
|
'ref_class_params',
|
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-03-17 13:55:39 +08:00
|
|
|
* @param Award|null $award
|
|
|
|
* @param User|null $user
|
|
|
|
* @return null
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
2018-03-17 13:55:39 +08:00
|
|
|
public function getReference(Award $award=null, User $user=null)
|
2018-03-17 13:18:03 +08:00
|
|
|
{
|
|
|
|
if (!$this->ref_class) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-03-17 13:55:39 +08:00
|
|
|
return new $this->ref_class($award, $user);
|
2018-03-17 13:18:03 +08:00
|
|
|
# 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
|
|
|
}
|