Simple and Easy Laravel 5.2 Login and Register using the auth scaffold
In this post we will give you information about Simple and Easy Laravel 5.2 Login and Register using the auth scaffold. Hear we will give you detail about Simple and Easy Laravel 5.2 Login and Register using the auth scaffoldAnd how to use it also give you demo for it if it is necessary.
Simple and Easy Laravel 5.2 Login and Register using the auth scaffold
Here i am going to use Laravel auth scaffolding to login and register, its very easy to integrate login and register system in Laravel.
Step 1: Install Laravel 5.2
If Laravel is not installed in your system then first install with following command and get fresh Laravel project.
composer create-project --prefer-dist laravel/laravel blog "5.2.*"
When you run above command then it create application with name blog in your system.From Laravel 5, you have to install laravelcollective/html for Form class.To know the installation process of laravelcollective/html, kindly go through this url HTML/FORM not found in Laravel 5?.
Step 2: Create users table and model
Follow the simple step to create users table in your database.First create migration for users table using Laravel 5 php artisan command,so first run this command –
php artisan make:migration create_users_table
After this command, you will see a migration file in following path database/migrations and you have to simply put following code in migration file to create users table.
- use IlluminateDatabaseSchemaBlueprint;
- use IlluminateDatabaseMigrationsMigration;
- class CreateUsersTable extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public functionup()
- {
- Schema::create('users',function(Blueprint $table){
- $table->increments('id');
- $table->string('name');
- $table->string('email')->unique();
- $table->string('password');
- $table->rememberToken();
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public functiondown()
- {
- Schema::drop('users');
- }
- }
use IlluminateDatabaseSchemaBlueprint;use IlluminateDatabaseMigrationsMigration;class CreateUsersTable extends Migration{ /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('users'); }}
Save this migration file and run following command
php artisan migrate
If you receive a “class not found” error when running migrations, try running the composer dump-autoload
command and re-issuing the migrate command.
Now you have successfully created ‘users’ table.You won’t have to create user model, it is created by default in following path app/User.php when you install Laravel.
- namespace App;
- use IlluminateFoundationAuthUser as Authenticatable;
- class User extends Authenticatable
- {
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable=[
- 'name','email','password',
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden=[
- 'password','remember_token',
- ];
- }
namespace App;use IlluminateFoundationAuthUser as Authenticatable;class User extends Authenticatable{ /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ];}
Step 3: The auth scaffold in Laravel 5.2
Laravel provide a short cut to create auth section
php artisan make:auth
After successfully run command, Laravel create complete auth section which you will see in your command promt –
List of files and folder which is generated by above command :
It generate a master layout which is core of scaffold resources/views/layouts/app.blade.php
List of views that extend it :
- welcome.blade.php – the welcome page
- home.blade.php – the landing page for logged-in users
- auth/login.blade.php – the login page
- auth/register.blade.php – the register or signup page
- auth/passwords/email.blade.php – the password reset confirmation page
- auth/passwords/reset.blade.php – the password reset prompt page
- auth/emails/password.blade.php – the password reset email
Changes in routes.php :
- Route::auth();
- Route::get('/home','HomeController@index');
Route::auth(); Route::get('/home', 'HomeController@index');
The Route::auth()
is a set of common authentication, registration and password reset routes.
- // Authentication Routes...
- $this->get('login','AuthAuthController@showLoginForm');
- $this->post('login','AuthAuthController@login');
- $this->get('logout','AuthAuthController@logout');
- // Registration Routes...
- $this->get('register','AuthAuthController@showRegistrationForm');
- $this->post('register','AuthAuthController@register');
- // Password Reset Routes...
- $this->get('password/reset/{token?}','AuthPasswordController@showResetForm');
- $this->post('password/email','AuthPasswordController@sendResetLinkEmail');
- $this->post('password/reset','AuthPasswordController@reset');
// Authentication Routes...$this->get('login', 'AuthAuthController@showLoginForm');$this->post('login', 'AuthAuthController@login');$this->get('logout', 'AuthAuthController@logout');// Registration Routes...$this->get('register', 'AuthAuthController@showRegistrationForm');$this->post('register', 'AuthAuthController@register');// Password Reset Routes...$this->get('password/reset/{token?}', 'AuthPasswordController@showResetForm');$this->post('password/email', 'AuthPasswordController@sendResetLinkEmail');$this->post('password/reset', 'AuthPasswordController@reset');
Benefits of using scaffolding in Laravel is you don’t have to create routes, controllers and views for login and register.It helps you to save 30 to 60 minutes of typing on every app that needs it.
Now let’s have a look at what we get in browser.
Hope this code and post will helped you for implement Simple and Easy Laravel 5.2 Login and Register using the auth scaffold. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs