Creating and validating a user using Ajax
When a user comes to our application, we may want them to register or login without the need to navigate to another page. Using Ajax within Laravel, we can submit the user's form and run the validation asynchronously.
Getting ready
For this recipe, we'll need a working installation of Laravel as well as a properly configured MySQL database. We also need to add a user table to our database, which we can do with the following code:
CREATE TABLE users (id int(10) unsigned NOT NULL AUTO_INCREMENT,email varchar(255) DEFAULT NULL,password char(60) DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
How to do it...
To complete this recipe, follow the given steps:
In the
controllers
directory, create aUsersController.php
file:<?php class UsersController extends BaseController { public function getIndex() { return View::make('users.index'); } public function postRegister() { $rules = array('email' => 'required|email','password...