MicroFrameWork/kernel/app_modules/photo/models/Photo.php

44 lines
996 B
PHP
Raw Permalink Normal View History

2024-11-29 13:23:48 +03:00
<?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;
}
}