Register

In this tutorial, i am going to teach you how to create register user in Laravel.

 

Step 1 : Create controller for register with the help of command.

php artisan make:controller RegisterController

eg:

 

Step 2 : Now create a route in web.php for show user register page.

Route::get('/register','RegisterController@index');

 

Step 3 : Now open your register controller to load register view page.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RegisterController extends Controller
{
    function index()
    {
        //Load register page here
    	return view('register');
    }

}

?>

 

Step 4 :  Create register view page (register.blade.php) in view folder, so that we can create design of user registration page.

<h2>Elevenstech Register</h2>

<!-- Show success message of register user -->
@if($message = Session::get('msg'))
  <div class="alert alert-success alert-block">
      <button type="button" class="close" data-dismiss="alert">X</button>
      <strong>{{$message}}</strong>
  </div>
@endif

<!-- Create user registration form -->
<form method="post" action="{{url('/store')}}">

  {{csrf_field()}}

  <div class="form-group">
    <label>Full Name : </label>
    <input type="text" name="fullname" class="form-control">
    <input type="hidden" name="token" class="form-control" value="{{csrf_token()}}">
  </div>

  <div class="form-group">
    <label>Email : </label>
    <input type="email" name="email" class="form-control">
  </div>

  <div class="form-group">
    <label>Password : </label>
    <input type="password" name="password" class="form-control">
  </div>

  <button type="submit" name="login" class="btn btn-primary">Register</button>
  <p>Already have an account <a href="{{url('/main')}}">Login Here</a></p>
  
</form>

 

Step 5 : Now create a route in web.php for user registration.

Route::post('/store','RegisterController@store');

 

Step 6 : Open your register controller and create a store function to store the user details.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\support\Facades\DB;
use Illuminate\support\Facades\Redirect;

class RegisterController extends Controller
{
    function index()
    {
    	return view('register');
    }

    //Create store function
    function store(Request $request)
    {
        //get all user details
    	$values = array(
    		'name' => $request->input('fullname'),
    		'email' => $request->input('email'), 
    		'password' => bcrypt($request->input('password')),
    		'remember_token' => $request->input('token')
    	);

        //insert user details in users table
    	DB::table('users')->insert($values);

        //back with success message
    	return Redirect::back()->with('msg','You have successfully registered.');
    }
    
}

?>

 

 


Result :

Source Code:

Small Laravel Project

In this project. We are providing you, how to create small project in Laravel....

Source Code