php Laravel 5 login Tutorial with Example of mysql DB

Hello Friends today we learn how to make a login system in laravel 5 framework.


Login Example with laravel 5 php mysql
Login Example with laravel 5 php mysql


Laravel 5 is new updated framework for web development. this framework is work with php 
language.
For making a login example we need first a Database or a table of users.

here is the steps for example

1 ] create a Database 
2 ] create a table called 'users'

mysql db or table for login example
mysql db

3 ] setup database configguration to laravel framework. for setup db config use '.env' file from root directory.

.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:jrE04yEKpu9X1zUT9qTraZBb0A4NiWJBDrGSEVyXtck=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravelLogin
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

4 ] create a view in resources/views/login.blade.php

<!DOCTYPE html>
<html>
    <head>
        <title>Laravel</title>

        <link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
    </head>
    <body>
       <center>
           <form action="/loginme" method="post">
               <input type="hidden" name="_token" value="{{ csrf_token() }}">
               USERNAME : <input type="text" name="username"><br/>
               PASSWORD : <input type="password" name="password"><br/>
               <input type="submit" name="login" value="Login">
           </form>
       </center>
    </body>
</html>


5 ] add below code to routes.php file "app/Http/routes.php

Route::get('/', function () {
    return view('login');
});



Route::post('/loginme','loginController@login');

6 ] create a controller file `loginController.php` in "app/Http/Controllers/loginController.php"

<?php
namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use DB;

class loginController extends BaseController
{
     public function login(Request $req)
     {
      $username = $req->input('username');
      $password = $req->input('password');

      $checkLogin = DB::table('users')->where(['username'=>$username,'password'=>$password])->get();
      if(count($checkLogin)  >0)
      {
      echo "Login SuccessFull<br/>";;
      }
      else
      {
      echo "Login Faield Wrong Data Passed";
      }
     }
}

?>


Now Go to you laravel root directory from CMD and write commant to start laravel server.

php artisan serve

this command start server ar 'http://localhost:8000'

you can test you app  here


Previous
Next Post »

21 comments

Write comments
netlify
AUTHOR
October 6, 2016 at 10:27 PM delete

it's good tutoriel , thank you for this tutoriel
where to find the loginme file

Reply
avatar
admin
AUTHOR
October 7, 2016 at 10:50 AM delete

loginme is not a file loginme is route name where i assign a controller and login code define in controller please watch full video for complete example.

Reply
avatar
Leo Pyae
AUTHOR
May 12, 2017 at 1:18 PM delete

1. Login page
login page will have login form:
fields:
email, password
button:
login
login details need to be checked from db users table.
if login success - redirect to clients page
if failed - display incorrect login message
form needs to be submitted with ajax, messages to show without page refresh
2. Clients page
this page will be only accessible for logged in admin user
contains list of clients (5 items per page) with pagination
columns sortable (clicking column title will switch sort order of listing, both pagination and sort functions need to work without page reloading):
firstname
lastname
email
company
title
phone
actions
actions for each entry:
edit, delete
button: create new
create new and edit links will lead to edit page for creating or editing entry
delete will remove after confirmation dialog showing up to user and he confirms
3. Client edit page
form for editing client:
fields:
firstname (input)
lastname (input)
email (input) (should be valid email)
company (input)
title (input)
phone (input) (should be valid phone)
bio (textarea)
buttons:
save, cancel
save - validates data and if ok - saves and redirects to Clients page
cancel - returns to Clients page
form needs to be submitted with ajax, messages to show without page refresh

Sir Im a student from Myanmar and i dont know how to build this type of forms. Can you help me sir please?? pyaesonesoe.student@gmail.com this is my email address sir. if you would help me reply me sir,I'll be waiting your reply sir.


Best Regards
Pyae Sone Soe

Reply
avatar
shoaib
AUTHOR
August 17, 2017 at 1:56 PM delete

/loginme is not found what to do

Reply
avatar
Unknown
AUTHOR
September 22, 2017 at 3:21 PM delete

"I very much enjoyed this article.Nice article thanks for given this information. i hope it useful to many pepole.php jobs in hyderabad.
"

Reply
avatar
SEO Services
AUTHOR
November 22, 2017 at 1:33 PM delete

It’s a very informative and helpful article, thank you for sharing!


Reply
avatar
Pk
AUTHOR
December 16, 2017 at 1:53 PM delete

For eg:
action = "http://localhost:88/laravel1/public/loginme"

do as user port number-88,
laravel folder name-laravel1
public is folder containing index.php
THen,it comes to login me

Reply
avatar
Shailendra
AUTHOR
January 16, 2018 at 3:35 PM delete

i read your content. it's unique and great informative.so please share some more content.
PHP Training institute in Gurgaon

Reply
avatar
Unknown
AUTHOR
January 23, 2018 at 5:07 PM delete

I would like to have more information about this, it is very informative...Thanks for sharing.
Laravel Development Services I Web Development Projects

Reply
avatar
BrnInfotech
AUTHOR
March 1, 2018 at 5:45 PM delete

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
mobile app training institutes

Reply
avatar
Unknown
AUTHOR
October 24, 2018 at 1:33 AM delete

Not working for me. What to do?

Reply
avatar
Unknown
AUTHOR
October 24, 2018 at 1:34 AM delete

Not working for me. What to do?

Reply
avatar
Anonymous
AUTHOR
May 2, 2020 at 5:53 PM delete

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password' in 'where clause' (SQL: select * from `users` where (`username` = admin and `password` = admin123))

im facing this error, in first attempt it works but from second attempt till now it gives me this error.
plz help!

Reply
avatar
August 27, 2020 at 2:51 PM delete

Keep sharing on new topic like this.
That's right.
Hire the strong team of Laravel Development Company that gives complete maintenance and support systems from initial to end.
Laravel Company

Reply
avatar
October 27, 2020 at 6:30 PM delete

Hello, Such a nice article. Great Share. Also, if You Are Looking for similar article then visit our website, We are technology/news/smartphone company, If you want to read such useful news then, Visit us: https://techmie.com/

Reply
avatar
November 6, 2020 at 3:33 PM delete

Get a free quote for laravel web development requirements from a top laravel development company in Australia, UK, USA, Delhi, Noida, Gurugram, Ghaziabad, Faridabad. For more information visit our website.


Laravel development company

Reply
avatar
April 13, 2021 at 10:05 AM delete

Appreciate for this!
The expert Shopify Developer and WordPress Developer provide phenomenal website architecture of your business.

Reply
avatar
See how can
AUTHOR
October 24, 2021 at 1:56 PM delete

The information you've shared here is informative because it contains some great knowledge which is extremely helpful on my behalf. Thanks for posting it. Keep it up. best php institute in delhi

Reply
avatar

Ask Your Question here ConversionConversion EmoticonEmoticon