Today, We want to share with you laravel login and registration example.In this post we will show you laravel authentication tutorial, hear for laravel 5.4 login and registration tutorial we will give you demo and example for implement.In this post, we will learn about
Get Current login Auth user details using Laravel with an example.
login register in laravel 7
There are the Following The simple About laravel 6 login and registration Full Information With Example and source code.
As I will cover this Post with live Working example to develop laravel 7 api authentication, so the laravel login without auth is used for this example is following below.
Step 1: laravel login and registration Auth
Execute php artisan make:auth in terminal.
php artisan make:auth
Execute php artisan migrate in terminal.
php artisan migrate
If you want customization( Adding username)
- First of all Execute php artisan make:auth in CMD using terminal.
- Open create_users_table.php migration file and included the bellow line
$table->string(‘username’,191)->nullable()->unique(); - Execute php artisan migrate in CMD via terminal
- And then last step open RegisterController.php and included bellow line.
protected function validator(array $data) { return Validator::make($data, [ 'name' => 'required|string|max:255', 'username' => 'required|string|max:191|unique:users', 'email' => 'required|string|email|max:191|unique:users', 'password' => 'required|string|min:6|confirmed', ]); } protected function create(array $data) { return User::create([ 'name' => $data['name'], 'username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); }
Step 2: Laravel model
User.php
protected $fillable = [ 'name', 'email', 'password','username', ];
Step 3: View File
resources/views/auth/register.blade.php
@if ($errors->has('username')) {{ $errors->first('username') }} @endif
Step 4: Laravel Controller
LoginController.php
use Illuminate\Http\Request; protected function credentials(Request $request) { $field = filter_var($request->get($this->username()), FILTER_VALIDATE_EMAIL) ? $this->username() : 'username'; return [ $field => $request->get($this->username()), 'password' => $request->password, ]; }
login.blade.php
Only update the type of Email field from email address to text and update custom label
pages you want to get or fetch only after login then included the bellow laravel code in respective laravel controller files
public function __construct() { $this->middleware('auth'); }
If you want to set admin and user custom session add bellow laravel code
protected function authenticated(Request $request, $user) { $request->session()->put('admin', 'admin'); return redirect()->intended($this->redirectPath()); }
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about laravel login and registration example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.