2018-01-29 03:19:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2022-03-14 23:45:18 +08:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
/**
|
2018-03-17 13:18:03 +08:00
|
|
|
* The Award model
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @property mixed id
|
2022-03-14 23:45:18 +08:00
|
|
|
* @property string name
|
|
|
|
* @property string description
|
|
|
|
* @property string title
|
|
|
|
* @property string image
|
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
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Award extends Model
|
2018-01-29 03:19:35 +08:00
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
use HasFactory;
|
|
|
|
|
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',
|
2018-04-02 03:32:01 +08:00
|
|
|
'ref_model',
|
|
|
|
'ref_model_params',
|
2022-01-11 04:49:50 +08:00
|
|
|
'active',
|
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',
|
2018-04-02 03:32:01 +08:00
|
|
|
'ref_model' => 'required',
|
2018-08-27 00:40:04 +08:00
|
|
|
'ref_model_params' => 'nullable',
|
2022-01-11 04:49:50 +08:00
|
|
|
'active' => 'nullable',
|
2018-01-29 03:19:35 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2018-03-17 13:18:03 +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
|
|
|
*
|
2018-03-17 13:55:39 +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-03-17 13:18:03 +08:00
|
|
|
{
|
2018-04-02 03:32:01 +08:00
|
|
|
if (!$this->ref_model) {
|
2018-08-27 00:40:04 +08:00
|
|
|
return;
|
2018-03-17 13:18:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-04-02 03:32:01 +08:00
|
|
|
return new $this->ref_model($award, $user);
|
2018-03-17 13:18:03 +08:00
|
|
|
} catch (\Exception $e) {
|
2018-08-27 00:40:04 +08:00
|
|
|
return;
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
2018-03-17 13:18:03 +08:00
|
|
|
}
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|