Laravel 5 to use existing validation to AngularJS
Asked Answered
A

1

6

Hi I have a problem in laravel 5 existing 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',
    ];
}}

It will return the validation of an email as an example. What I want to do with my angularjs is I want to catch validation and fetch it on my front-end form. It will not reload the page. Do you have any idea about this one?

Form from my application will send data through angularjs. $http post url "app/postPage" and if it has an error above my code will $validation->messages() will send to my angularjs.

Athodyd answered 29/7, 2015 at 12:40 Comment(1)
what does catch and fetch mean? Question is not very clear. Please be more specific what you are exactly trying to do.Signboard
G
4

You can do following.

  • Make a POST route for validation lets say myapp.com/validateEmail
  • Send the data which you want to validate to this route using $http request of anuglarJS. Lets say Email
  • Validate the data and return validation object as JSON. You can send JSON response like that. JSON Responses from docs
  • Read this JSON in scope model in angularjs controller. In the success() of 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 appropriate error based on scope in HTML.

Gradely answered 29/7, 2015 at 13:36 Comment(1)
that is my problem how will I send the validation data to my angularjs code.Athodyd

© 2022 - 2024 — McMap. All rights reserved.