Hello Friends today we learn how to make a login system in laravel 5 framework.
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'
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
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 |
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
21 comments
Write commentsit's good tutoriel , thank you for this tutoriel
Replywhere to find the loginme file
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.
Reply1. Login page
Replylogin 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
/loginme is not found what to do
Reply"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"
It’s a very informative and helpful article, thank you for sharing!
ReplyFor eg:
Replyaction = "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
i read your content. it's unique and great informative.so please share some more content.
ReplyPHP Training institute in Gurgaon
I would like to have more information about this, it is very informative...Thanks for sharing.
ReplyLaravel Development Services I Web Development Projects
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
Replymobile app training institutes
good tutorial
ReplyThank you
ReplyNot working for me. What to do?
ReplyNot working for me. What to do?
ReplyThanks
ReplySQLSTATE[42S22]: Column not found: 1054 Unknown column 'password' in 'where clause' (SQL: select * from `users` where (`username` = admin and `password` = admin123))
Replyim facing this error, in first attempt it works but from second attempt till now it gives me this error.
plz help!
Keep sharing on new topic like this.
ReplyThat's right.
Hire the strong team of Laravel Development Company that gives complete maintenance and support systems from initial to end.
Laravel Company
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/
ReplyGet 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.
ReplyLaravel development company
Appreciate for this!
ReplyThe expert Shopify Developer and WordPress Developer provide phenomenal website architecture of your business.
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
ReplyAsk Your Question here ConversionConversion EmoticonEmoticon