Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Handlers/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SMartins\Exceptions\Handlers;

use Throwable;
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
Expand Down Expand Up @@ -55,7 +56,7 @@ abstract class AbstractHandler
*
* @param Exception $e
*/
public function __construct(Exception $e)
public function __construct(Throwable $e)
{
$this->exception = $e;
}
Expand Down
27 changes: 20 additions & 7 deletions src/Handlers/ValidationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ public function handle()
*/
public function getValidationTitle(array $failedFieldsRules, string $key, string $field)
{
$title = __('exception::exceptions.validation.title', [
'fails' => strtolower(array_keys($failedFieldsRules[$field])[$key]),
'field' => $field,
]);
if (empty($failedFieldsRules)) {
$fails = '';
} else {
$fails = strtolower(array_keys($failedFieldsRules[$field])[$key]);
}

return is_array($title) ? $title[0] : $title;
$title = __('exception::exceptions.validation.title', [
'fails' => $fails,
'field' => $field,
]);

if (is_array($title)) {
$title = $title[0];
}

return ucfirst(trim($title));
}

/**
Expand All @@ -66,9 +76,12 @@ public function getValidationTitle(array $failedFieldsRules, string $key, string
*/
public function getValidationCode(array $failedFieldsRules, string $key, string $field)
{
$rule = strtolower(array_keys($failedFieldsRules[$field])[$key]);
if (empty($failedFieldsRules)) {
return config('json-exception-handler.codes.validation');
}

return config('json-exception-handler.codes.validation_fields.'.$field.'.'.$rule);
$rule = strtolower(array_keys($failedFieldsRules[$field])[$key]);
return config('json-exception-handler.codes.validation_fields.' . $field . '.' . $rule);
}

/**
Expand Down