mardi 14 février 2017

How can I use Laravel Validation in the API, it's returning my view now?

I have this route in route/api.php:

Route::post('/register', 'LoginController@register');

My LoginController

class LoginController extends Controller {

public function register(Request $request) {
    $this->validate($request, // <-- using this will return the view
      // from **web.php** instead of the expected json response.
    [
        'email' => 'required|email',
        'firstName' => 'required|alpha_dash',
        'lastName' => 'required',
        'password' => 'required|confirmed',
    ]);

    $input = $request->all();
    //$plain_password = $input['password'];
    $input['uuid'] = uuid();
    $input['password'] = Hash::make($input['password']);

    $user = User::create($input);

    dd($errors);

    $response['succes'] = true;
    $response['user'] = $user;
    return response($response);
    }
}

Why does adding a validation call change the behaviour to returning my view / the wrong route. I want the api to validate my request too, not just my "frontend".



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kGViXa
via IFTTT

Aucun commentaire:

Enregistrer un commentaire