Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
<?php
namespace HiEvents\Http\Actions\Images;
use HiEvents\DomainObjects\Enums\ImageType;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\Request\Image\CreateImageRequest;
use HiEvents\Resources\Image\ImageResource;
use HiEvents\Services\Application\Handlers\Images\CreateImageHandler;
use HiEvents\Services\Application\Handlers\Images\DTO\CreateImageDTO;
use HiEvents\Services\Infrastructure\Image\Exception\CouldNotUploadImageException;
use Illuminate\Http\JsonResponse;
class CreateImageAction extends BaseAction
{
public function __construct(
public readonly CreateImageHandler $createImageHandler,
) {}
/**
* @throws CouldNotUploadImageException
*/
public function __invoke(CreateImageRequest $request): JsonResponse
{
$imageType = $request->has('image_type') ? ImageType::fromName($request->input('image_type')) : null;
if ($imageType !== null && $request->filled('entity_id')) {
$this->isActionAuthorized((int) $request->input('entity_id'), $imageType->getEntityType());
}
$image = $this->createImageHandler->handle(new CreateImageDTO(
userId: $this->getAuthenticatedUser()->getId(),
accountId: $this->getAuthenticatedAccountId(),
image: $request->file('image'),
imageType: $imageType,
entityId: $request->input('entity_id'),
));
return $this->resourceResponse(ImageResource::class, $image);
}
}