Setup Menus in Admin Panel

  • No products in the cart.

  • LOGIN

Laravel Authentication

Laravel makes implementing authentication very simple. Almost everything is configured for you out of the box. The authentication configuration file is located at config/auth.php, which contains several well documented options for tweaking the behavior of the authentication services.

Run the following command:

php artisan make:auth

 

 

Check the status :

git status

 

 

Now run the following url:

http://newsportal.test/login

By default you will see the following screenshot:

 

Screenshot :

 

Screenshot:

 

 

But we don’t need this type of form. So, we need to do some customization.

In the web.php file, we have seen only Auth::routes()
By default, it makes the bundle for login, register and forgot password.
So in order to check you have to run the following command:

php artisan route:list

It will display all the routes as below:

Screenshot:

 

Screenshot:

 

Search the showLoginForm

Step 1.

Go to this directory:

App\Http\Controllers\Auth\LoginController.php

 

Step 2.

Here you will find this step:

use AuthenticatesUsers;

So, search AuthenticatesUsers.php directory

AuthenticatesUsers.php directory:

vendor/laravel/framework/src/illuminate/Foundation/Auth/AuthenticatesUsers.php

In this directory you will find the following code:

public function showLoginForm()
{
return view('auth.login');
}

Step 3.

Go to the directory resources/views/auth/login.blade.php
Here we are not allowed to change the laravel default package but you can overwrite and copy the function and add it to the LoginController.php (Directory:App\Http\Controllers\Auth\LoginController.php).

code:
/**
* Show the application's login form.
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm()
{
return view('auth.login');
}

 

Remember:

Give the path for costumize login.blade.php in the above code.

return view('admin.auth.login')

Screenshot  before modification:

 

Screenshot after modification:

 

Create a auth directory inside resources/views/admin/..
and create login.blade.php file inside auth directory.

Copy the code of your login page and paste it to the login.blade.php.
This file is in resources/views/admin/login.blade.php directory.

If you run the url http://newsportal.test/login  you will see the following result:

 

Screenshot:

 

So you need to give the dynamic path for css and js.

Screenshot:

Remove the unnecessary link :
such as forget password, and I want to register.

Simply adding BKP in function showLoginForm() you will redirected to the laravel default login form:

public function showLoginFormBKP()
{
return view('admin.auth.login');
}

 

Here you need to notice the working mechanism of the login form.

1. Open login form and right click the mouse and select Inspect. Now hover the mouse over the form you will see the following result:

Screenshot:

 

method=”POST”

So go to App\Http\Controllers\Auth\[email protected] directory

Screenshot

In this directory vendor/laravel/framework/src/illuminate/Foundation/Auth/AuthenticatesUsers.php you can get the login:

Screenshot

Now replace the login form code:

resources/views/auth/login.blade.php

<form method="POST" action="{{ route('login') }}" aria-label="{{ __('Login') }}">

 

resources/views/admin/auth/login.blade.php

<form>

So instead of <form> copy the above code.
Then copy and paste @csrf which is below the form.

 

Cross-Site Request Forgery (CSRF):

It is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. CSRF attacks specifically target state-changing requests, not theft of data, since the attacker has no way to see the response to the forged request.

After using the @csrf you will see the following result:

Screenshot: 

 

And make some modification in input filed:

<input type="email" name="email" class="form-control" placeholder="Username" />

<input type="password" name="password"class="form-control" placeholder="Password" />

<input type="checkbox" name="remember" class="ace" />

<button type="submit" class="width-35 pull-right btn btn-sm btn-primary">

 

Screenshot:

 

Go to the url: http://newsportal.test/login

Valid case:
Enter the email id and password which you have already created

email [email protected]
pw:root

You will be redirected to the login and homepage.

 

Screenshot:login page

 

Screenshot:home page

 

Invalid case:

First copy the code error case code from resources/views/auth/login.blade.php

Code:
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif

 

Paste this above code in the  directory resources/views/admin/auth/login.blade.php below the <span>

Screenshot:

 

Screenshot

 

If you wish to change the error message color then you can change by adding the class name as an error.

Screenshot:

and add some style to class error below the head section:

<style>
.error {
color: rgba(132, 19, 41, 0.7);
}
</style>

 

Screenshot:

Attachments22

SEE ALL Add a note
YOU
Add your Comment
 

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.
X