phpvms/app/Models/Award.php

55 lines
1.0 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
2018-08-27 00:40:04 +08:00
*
* @property mixed id
2018-04-02 03:32:01 +08:00
* @property mixed ref_model
* @property mixed|null ref_model_params
2018-01-29 03:19:35 +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',
'image_url',
2018-04-02 03:32:01 +08:00
'ref_model',
'ref_model_params',
2018-01-29 03:19:35 +08:00
];
public static $rules = [
'name' => 'required',
'description' => 'nullable',
'image_url' => 'nullable',
2018-04-02 03:32:01 +08:00
'ref_model' => 'required',
2018-08-27 00:40:04 +08:00
'ref_model_params' => 'nullable',
2018-01-29 03:19:35 +08:00
];
/**
* Get the referring object
2018-08-27 00:40:04 +08:00
*
2018-08-27 02:50:08 +08:00
* @param self $award
* @param User|null $user
2018-08-27 00:40:04 +08:00
*
* @return null
2018-01-29 03:19:35 +08:00
*/
2018-08-27 00:40:04 +08:00
public function getReference(self $award = null, User $user = null)
{
2018-04-02 03:32:01 +08:00
if (!$this->ref_model) {
2018-08-27 00:40:04 +08:00
return;
}
try {
2018-04-02 03:32:01 +08:00
return new $this->ref_model($award, $user);
} catch (\Exception $e) {
2018-08-27 00:40:04 +08:00
return;
2018-01-29 03:19:35 +08:00
}
}
2018-01-29 03:19:35 +08:00
}