I want to manage all my events on a calendar and want to have all the information on one place on a website. What should I do? I think, I will use jQuery FullCalendar for it. If I am using WordPress, I can find so many plugins for full fling this requirement. But my problem… [Read More]
Laravel 5 Login with the Built-In Scaffolding
Laravel 5 is becoming the most favorite php framework in the running days. It has many advantages and securities rather than other php frameworks. Today, I am going to describe the Laravel 5 login with built-in scaffolding. We will be comprehensive and friendly during the whole article.
Ok. First, we have to have some idea about this scaffolding for Laravel 5 Login. Although, this scaffolding comes with many parts which makes easy our login process. Having these parts , we even don’t need to write a single line of code. So, here is the parts for this scaffolding.
- Auth controller
- Routing
- Views with Styling
Contents
Laravel 5 Login – Gettting Started:
Please install Laravel 5 and get environment setup with database connection using Laravel Homestead.
Once you see the Laravel in your browser, it’s good to proceed.
Routing
The routing file (app/Http/routes.php
) is one of the primary(first) files we work into as you start your Laravel application. If you want to look at the default routes file, you will see that the Laravel has already wired up the routes for the built-in authentication.
1 2 3 4 |
Route::controllers([ 'auth' => 'AuthAuthController', 'password' => 'AuthPasswordController', ]); |
User registration and logging users will be handled by the AuthController while the resetting the forgotten passwords will be handled by the PasswordController.
As we are routing the controller to 'auth'
, then all the routes on that controller will be nested under /auth/. For Instance, our route will be http://laravel.app/auth/login.
These both type of routes are implicit controllers. It means that the routing is defined by the controller itself. You just need to add the HTTP verb in your function(method) and routing will be handled by Laravel.
AuthController
Have a look in the AuthAuthController
(located at app/Http/Controllers/Auth/AuthController.php), you will find that another file is referenced that has a trait: IlluminateFoundationAuthAuthenticatesAndRegistersUsers
. Please don’t change this file. If you really want to customize this , the views are main choice.
If we deeply analyse that file, we’ll see that there are the following methods and routes:
Method Name | URL | Description |
---|---|---|
getRegister() | GET http://laravel.app/auth/register | Show the register page |
postRegister() | POST http://laravel.app/auth/register | Process the register form |
getLogin() | GET http://laravel.app/auth/login | Show the login form |
postLogin() | POST http://laravel.app/auth/login | Process the login form |
Everything is here for us. We don’t need to do anything else. The routing, views, authentication mechanisms, and controllers are there for us. Let’s start the game an try some of the features of the built-in scaffolding and try to register a user.
But before going ahead, we have to fully set our database. Without this step, if we try to register a user at http://laravel.app/auth/register, we will face the problems.
Database Migrations
This error is here because we don’t have the tables in database. If there is no user table in the database, how can we save a user? We need to create a migration to create user table.
Luckily, the migrations are also included in the scaffolding! We just have to SSH into our VM, find the root folder of our application, and run the migration.
1 2 3 4 5 6 7 8 |
# ssh into our vm $ homestead ssh # find our directory $ cd laravel # run the migrations $ php artisan migrate |
Registering
Let’s try again and register a user etc. You will not see that error message.
By examining the MySQL tables, we’ll see there three new tables with the names users, password_resets, and migrations.
If you click on the users table , you will see the new user with hash password.
Logging In
Now, try to login with a wrong email and password. You will see the error. If we use correct details, we will be on the home page with welcome message.
Conclusion
You noticed that we did not write a single line of code for Laravel 5 Login and we develop a new login and registration form. Stay with us for further tutorials.
Leave a Reply