Navigation bar dropdown menu not working properly in Laravel 8
P粉460377540
P粉460377540 2023-12-16 11:55:20
0
1
579

I'm having an issue with the navigation bar in Laravel 8; specifically, the entire navigation bar shows up on the view, but the dropdown menu doesn't work.

In fact, when I click, the dropdown menu does not open.

This is layout.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="{{asset('css/app.css')}}">
    <title>Document</title>
</head>
<body>
    
    <x-navbar/>
    
    {{$slot}}

    <script src="{{asset('js/app.js')}}"></script>
</body>
</html>

This is navbar.blade.php:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>

And the home.blade.php view is:

<x-layout>
    <h1>Hello!!!</h1>
</x-layout>

P粉460377540
P粉460377540

reply all(1)
P粉851401475

Please try this method, otherwise you may get spelling errors.

@include('inc.navbar')
//      @include('FOLDER_NAME.FILE_NAME')

Also check the documentation! https://laravel.com/docs/9.x/blade#include-subview

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template