2018-01-29 03:19:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Model;
|
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
/**
|
2018-03-17 13:18:03 +08:00
|
|
|
* The Award model
|
2018-03-20 09:50:40 +08:00
|
|
|
* @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
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Award extends Model
|
2018-01-29 03:19:35 +08:00
|
|
|
{
|
|
|
|
public $table = 'awards';
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2018-03-18 01:17:38 +08:00
|
|
|
'name',
|
2018-01-29 03:19:35 +08:00
|
|
|
'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-20 09:50:40 +08:00
|
|
|
'name' => 'required',
|
|
|
|
'description' => 'nullable',
|
|
|
|
'image_url' => 'nullable',
|
|
|
|
'ref_class' => 'required',
|
2018-03-18 01:17:38 +08:00
|
|
|
'ref_class_params' => '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
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param User|null $user
|
2018-03-17 13:55:39 +08:00
|
|
|
* @return null
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +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
|
|
|
} 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
|
|
|
}
|