photo module
This commit is contained in:
44
kernel/app_modules/photo/models/Photo.php
Executable file
44
kernel/app_modules/photo/models/Photo.php
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\photo\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $image
|
||||
* @property string $entity
|
||||
* @property int $entity_id
|
||||
*/
|
||||
class Photo extends Model
|
||||
{
|
||||
protected $table = 'photo';
|
||||
|
||||
protected $fillable = ['image', 'entity', 'entity_id'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'image' => 'Фото',
|
||||
'entity' => 'Сущность',
|
||||
'entity_id' => 'Идентификатор сущности',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPhotoListByEntity(string $entity): array
|
||||
{
|
||||
return self::where("entity", $entity)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getPhotoByEntity(string $entity): array
|
||||
{
|
||||
$result = [];
|
||||
$photos = self::getPhotoListByEntity($entity);
|
||||
foreach ($photos as $photo) {
|
||||
$result[$photo['id']] = $photo['label'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
19
kernel/app_modules/photo/models/form/CreatePhotoForm.php
Executable file
19
kernel/app_modules/photo/models/form/CreatePhotoForm.php
Executable file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\photo\models\form;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreatePhotoForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'image' => 'required',
|
||||
'entity' => 'required|string',
|
||||
'entity_id' => 'required|integer|min:1',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user