44 lines
996 B
PHP
44 lines
996 B
PHP
|
<?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;
|
||
|
}
|
||
|
|
||
|
}
|