photo module

This commit is contained in:
2024-11-29 13:23:48 +03:00
parent e7a20d9b97
commit 3ef1e7d7e0
17 changed files with 464 additions and 71 deletions

View 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;
}
}

View 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',
];
}
}