36 lines
855 B
PHP
36 lines
855 B
PHP
<?php
|
|
|
|
namespace App\Exceptions\Regulacao;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\Response;
|
|
|
|
class CannotStoreSolicitacaoException extends Exception
|
|
{
|
|
protected $itens;
|
|
|
|
public function __construct(array $itens)
|
|
{
|
|
$this->itens = $itens;
|
|
$this->message = 'O(s) seguinte(s) procedimento(s) já foi(ram) solicitado(s): <strong>'
|
|
. implode(', ', $this->formatItens($itens))
|
|
. '</strong>. Deseja continuar?';
|
|
|
|
}
|
|
|
|
protected function formatItens(array $itens)
|
|
{
|
|
return array_map(function ($item) {
|
|
return $item['nome'] ?? 'Item desconhecido';
|
|
}, $itens);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return response()->json([
|
|
'message' => $this->message,
|
|
'itens' => $this->formatItens($this->itens)
|
|
], Response::HTTP_CONFLICT);
|
|
}
|
|
}
|