phpvms/app/Models/Award.php

53 lines
1.1 KiB
PHP
Raw Normal View History

2018-01-29 03:19:35 +08:00
<?php
namespace App\Models;
use App\Interfaces\Model;
2018-01-29 03:19:35 +08:00
/**
* The Award model
* @property mixed id
* @property mixed ref_class
* @property mixed|null ref_class_params
2018-01-29 03:19:35 +08:00
* @package Award\Models
*/
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',
'image_url',
'ref_class',
'ref_class_params',
2018-01-29 03:19:35 +08:00
];
public static $rules = [
'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
];
/**
* Get the referring object
* @param Award|null $award
* @param User|null $user
* @return null
2018-01-29 03:19:35 +08:00
*/
public function getReference(Award $award = null, User $user = null)
{
if (!$this->ref_class) {
return null;
}
try {
return new $this->ref_class($award, $user);
} catch (\Exception $e) {
return null;
2018-01-29 03:19:35 +08:00
}
}
2018-01-29 03:19:35 +08:00
}