Laravel 8 E-Commerce - Make the Header Functional on Login and Register Page

In this video, we will learn how to make the header functional on the login and register page.

Let's explore how to achieve this.

As you can see, this is the login page, and currently, the search box, wishlist, and cart are not working.

If I search for anything, it doesn't show the search results.

Similarly, clicking on the wishlist icon doesn't trigger any action, and the cart icon is also non-functional.

Let's make these features work.

Switch to your project and create a new component class file.

Go to the app directory, then views/components, and create a new file named BaseLayout.php.

Open this file and add the following code:


<?php

namespace App\View\Components;

use Illuminate\View\Component;

class BaseLayout extends Component
{
/**
* Get the view / contents that represents the component.
*
* @return \Illuminate\View\View
*/
public function render()
{
return view('layouts.base');
}
}

Save this file and navigate to the resources directory, then views.

Open the auth directory and find the login.blade.php file.

In this file, make only one change: update the layout tag name.


<x-base-layout>
<main id="main" class="main-site left-sidebar">

<div class="container">

<div class="wrap-breadcrumb">
<ul>
<li class="item-link"><a href="/" class="link">home</a></li>
<li class="item-link"><span>login</span></li>
</ul>
</div>
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12 col-md-offset-3">
<div class=" main-content-area">
<div class="wrap-login-item ">
<div class="login-form form-item form-stl">
<x-jet-validation-errors class="mb-4" />
<form name="frm-login" method="POST" action="{{route('login')}}">
@csrf
<fieldset class="wrap-title">
<h3 class="form-title">Log in to your account</h3>
</fieldset>
<fieldset class="wrap-input">
<label for="frm-login-uname">Email Address:</label>
<input type="email" id="frm-login-uname" name="email" placeholder="Type your email address" :value="old('email')" required autofocus>
</fieldset>
<fieldset class="wrap-input">
<label for="frm-login-pass">Password:</label>
<input type="password" id="frm-login-pass" name="password" placeholder="************" required autocomplete="current-password">
</fieldset>

<fieldset class="wrap-input">
<label class="remember-field">
<input class="frm-input " name="remember" id="rememberme" value="forever" type="checkbox"><span>Remember me</span>
</label>
<a class="link-function left-position" href="{{route('password.request')}}" title="Forgotten password?">Forgotten password?</a>
</fieldset>
<input type="submit" class="btn btn-submit" value="Login" name="submit">
</form>
</div>
</div>
</div><!--end main products area-->
</div>
</div><!--end row-->

</div><!--end container-->

</main>
</x-base-layout>

Let's check the result.

Switch to your browser and refresh the page.

Now, try searching for anything.

This time, you can see that it's working correctly.

Additionally, the wishlist and cart icons are also functional.

Repeat the same process to update the layout name in the register, forget-password, and reset-password view files.

By following these steps, you can make the header functional on the login and register page.