Skip to content

Commit

Permalink
[4.x] Check if form request wantsJson (#9533)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Feb 20, 2024
1 parent 8c2a481 commit e0d10d5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Http/Controllers/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function validateContentType($request, $form)
*/
private function formFailure($params, $errors, $form)
{
if (request()->ajax()) {
if (request()->ajax() || request()->wantsJson()) {
return response([
'errors' => (new MessageBag($errors))->all(),
'error' => collect($errors)->map(function ($errors, $field) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/FrontendFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function validator()

protected function failedValidation(Validator $validator)
{
if ($this->ajax()) {
if ($this->ajax() || $this->wantsJson()) {
$errors = $validator->errors();

$response = response([
Expand Down

0 comments on commit e0d10d5

Please sign in to comment.