Laravel 5 use existing validation for AngularJS

Hi, I have a problem in existing laravel 5 validation.

In my controller and request.

class PostEmailRequest extends Request{ /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'email' => 'required|max:255', ]; }} 

As an example, it will return an email confirmation. What I want to do with my angularjs is that I want to check the validation and get it in my interface form. It will not reload the page. Do you have any idea about this?

The form from my application will send data via angularjs. $ http post url "app / postPage", and if it has an error above my code, then $ validation-> messages () will send my angularjs.

+6
source share
1 answer

You can do the following.

  • Make a POST route for verification lets say myapp.com/validateEmail
  • Send the data you want to check for this route using the $http anuglarJS request. Let's say Email
  • Validate the data and return the validation object as JSON. You can send a JSON response this way. JSON Answers from the documentation
  • Read this JSON in the scope model in the angularjs controller. In success() following code.

     $http.post('/someUrl', {msg:'hello word!'}). success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available }). error(function(data, status, headers, config) { // called asynchronously if an error occurs // or server returns response with an error status. }); 
  • Show corresponding error based on scope in HTML .

+4
source

All Articles