Last active
May 28, 2016 00:02
-
-
Save mindesik/b37851fd72f993edc38a287555a96f01 to your computer and use it in GitHub Desktop.
Laravel ajax and php request with errors validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajax({ | |
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, // required | |
method: // | |
data: // | |
url: // | |
}).error(function (response) { | |
if (response.responseJSON.errors) { | |
console.log(response.responseJSON.errors); | |
} | |
}).always(function () { | |
console.log('response returned'); | |
}).success(function () { | |
console.log('request success'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Requests; | |
use App\Http\Requests\Request; | |
use Illuminate\Contracts\Validation\Validator; | |
class EntryRequest extends Request { | |
/** | |
* Custom errors validator. | |
* | |
* @access protected | |
* @param Validator $validator | |
* @return array | |
*/ | |
protected function formatErrors(Validator $validator) | |
{ | |
return ['errors' => $validator->errors()->all()]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment