Project Tutorials
Introduction of Laravel Setup and Installation of Laravel Project Laravel Structure Create Login Page Design Validation on Login Login with Database Display Username after Login Logout Register Design Dashboard Page Add Product List Products from Database Edit product from database Active Inactive user statusRegister
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 CodeElevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date