0

I'm getting a routing error with my jquery validation. mostly in my exp. Laravel is not accepting URL with ? in it. I'm not sure if I'm wrong or I'm just doing it wrong.

the URL I'm generating is canvas/users/validate?email=email@email.com

JavaScript

email: {
            required: true,
            email: true,
            remote: {
                    url:  'canvas/users/validate?',
                    type: "GET"
            }
        },

route.php

Route::get('canvas/users/validate?email={email}',
                array('uses'=>'Canvas\UserController@validateEmail'));

controller.php

protected function validateEmail($email) {
        $user = User::where('email',$email)->get();
        if ($user->isEmpty()){
            return 'false';
        }else{
            return 'true';
        }
    }
Karlo
  • 95
  • 3
  • 9
  • Within PHP, the response should be `echo 'true'` or `echo 'false'`... not `return`. – Sparky Nov 28 '15 at 16:14
  • Also see: http://stackoverflow.com/questions/16577120/jquery-validate-remote-method-usage-to-check-if-username-already-exists – Sparky Nov 28 '15 at 16:15

2 Answers2

0

try to include full URL like this:

  url:  "{{ url('canvas/users/validate?') }}",

if you using balde templates, you can use those curly braces else use the php echo

0

Here is my code . Its working

Jquery

email: {
                    required: true,
                    email: true,
                    remote: {
                        url:  "{{ url('admin/checkemailexists') }}",
                        type: "post"
                    }
                }

Route

Route::post(ADMIN.'/checkemailexists', array('uses'=>'admin\AdminController@checkemailexists'));

Controller

protected function checkemailexists(Request $request) {
          if($request->Input('email')){
               $user = admins::where('email',$request->Input('email'))->first();
        if ($user){
            return 'false';
        }else{
            return 'true';
        }
          }

    }
Meera
  • 107
  • 1
  • 1
  • 12