Setup Menus in Admin Panel

  • No products in the cart.

  • LOGIN

Logout and Dashboard Section

Logout section:


Similar to the showLoginForm, you cannot modify in the vendor section so copy the function logout part and add it to the LoginController.php

public function logout(Request $request)
{
$this->guard()->logout();

$request->session()->invalidate();

return $this->loggedOut($request) ?: redirect()->route('login');
}

 

Note:
Don’t forget to add the following line of code at the top of the LoginController.php code:

use Illuminate\Http\Request;

As soon as when you click the logout button you will redirect to the login page.

 

 

Dashboard section:


After the successful login, it should be redirected to the dashboard.
For this, you can simply provide the url path in the LoginController.php.
In this case, you can’t provide the route path.

protected $redirectTo = 'admin/dashboard';

Till now login section is almost completed but logout section is still not completed.

So go to the directory resources/views/admin/layout/master.blade.php and find out the logout section.
Now run the url http://newsportal.test/home and click on the logout section then right click to inspect the code. Then you will see the following result and copy the outerHTML and paste it to the master.blade.php below the tag <a>…</a>

<a href="#" onclick="event.preventDefault();
document.getElementById('logout-form').submit();" class="dropdown-item">
Logout
</a>

 

Screenshot:

 

 

 

Screenshot:

 

And copy the form also which is below the logout section:

<form id="logout-form" action="http://newsportal.test/logout" method="POST" style="display: none;">
<input type="hidden" name="_token" value="CYMGpxOloARikXmdCJc8HBfo84RHACwAPghA3uPE">
</form>

 

and make the path dynamic:

action="{{ route('logout') }}"

and the input field shouldn’t be displayed. So perform the following:

{!! csrf_field() !!}

So after clicking the logout section, you will redirect to the login page.

 

 

Middleware:


Suppose, when we run the url http://newsportal.test/admin/dashboard you will redirect to the dashboard. But in our real work project, this shouldn’t happen.So when we run the url http://newsportal.test/admin/dashboard it should redirect to the login page for this purpose we use the middleware.
Go to the web.php and add the middleware function as in below screenshot below:

 

 

We can also optimize the path by using the prefix as below:
web.php

Route::group([ 'prefix' => 'admin/', 'as' => 'admin.', 'middleware' => 'auth'],function()

 

Screenshot:

 

Now adding the route for news, edit, update and delete
web.php

Route::get('user/store', [ 'as'=> 'user.store', 'uses' => 'Admin\[email protected]']);
Route::get('user/edit/{id}', [ 'as'=> 'user.edit', 'uses' => 'Admin\[email protected]']);
Route::get('user/update/{id}', [ 'as'=> 'user.update', 'uses' => 'Admin\[email protected]']);
Route::get('user/delete/{id}', [ 'as'=> 'user.delete', 'uses' => 'Admin\[email protected]']);

 

Attachments5

SEE ALL Add a note
YOU
Add your Comment
 

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.
X