Expected Output(show most of the time)
<li class="m-menu__item m-menu__item--active " aria-haspopup="true" data-menu-submenu-toggle="hover">
<a href="http://127.0.0.1:8000/invoices" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-clipboard"></i>
<span class="m-menu__link-text">
Invoices
</span>
</a>
</li>
Broken Html(sometimes throws output with broken tags)
<li class="m-menu__item m-menu__item--active " aria-haspopup="true" data-menu-submenu-toggle="hover">
<a href="http://127.0.0.1:8000/invoices" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-clipboard"></i>
<s </span>
</a>
</li>
blade code
<li class="m-menu__item #if(isset($sidebar) && $sidebar == 'invoice') m-menu__item--active #endif" aria-haspopup="true" data-menu-submenu-toggle="hover">
<a href="{{ asset('invoices') }}" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-clipboard"></i>
<span class="m-menu__link-text">
Invoices
</span>
</a>
</li>
tried enabling errors, logging disabling cache but still no luck
is there some error in blade rendering
Try to improve your code, but may not fix the bug.
<li class="m-menu__item {{ isset($sidebar) && $sidebar == 'invoice' ? 'm-menu__item--active' : '' }}" aria-haspopup="true" data-menu-submenu-toggle="hover">
<a href="{{ url('/invoices') }}" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-clipboard"></i>
<span class="m-menu__link-text">
Invoices
</span>
</a>
</li>
use asset() function only to load asset files (JS, CSS, images)
use url('uri') on anchor or route('route-name') even better
Related
Im developing a blog in laravel hosted in apache. Im using laravel mix for compiling my assets (css, js).
When I go to some route, the page takes less than 1 second to charge the css:
The elapsed time is very short, however it is very annoying. Why does this happen?
I know that the answer can come from many factors and the only thing that occurs to me is something wrongly configured in laravel mix but my js and css assets only have a couple of codes.
For example this also happens on my home page (index) which have a very simple code (except for the menu bar). the code of my Home page:
home.blade.php
<html>
#extends('layout/layout')
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Blog</title>
</head>
<body>
<div class="contenedor">
#include('menu/menu-nav')
<h1>Bienvenidos al Blog!</h1>
</div>
</body>
</html>
layout.blade.php
<script src="{{ asset('js/app.js') }}"></script>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
menu-nav.blade.php
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
#if(Auth::check())
<a class="navbar-brand" href={{ route('editProfile')}}>
{{ Auth::user()->username }}
</a>
#endif
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href={{ route('home') }} >Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href={{ route('viewposts') }}>Blog</a>
</li>
#if(Auth::user())
#if(Auth::user()->hasRole('creator'))
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Posts
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href={{ route('createpost') }}>Crear Post</a>
<a class="dropdown-item" href="#">Editar Post</a>
</div>
#endif
#endif
#if(Auth::user())
#if(Auth::user()->hasRole('admin'))
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Administración
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="{{ route('viewusers') }}">Usuarios</a>
<a class="dropdown-item" href="#">Estadísticas</a>
</div>
#endif
#endif
</ul>
#if(Auth::user())
<span class="navbar-text">
<a class="nav-link" href={{ route('logout') }}>Log out</a>
</span>
#else
<span class="navbar-text">
<a class="nav-link" href={{ route('register') }}>Registrarse</a>
</span>
<span class="navbar-text">
<a class="nav-link" href={{ route('login') }}>Log in</a>
</span>
#endif
</div>
I would recommend you place the CSS and JS tags into the <head> section, as explained here: https://stackoverflow.com/a/18392465/14481105 the browser looks for those files inside the head section.
I'm not sure if you have just omitted it for Stack Overflow purposes but you also want the <html> tags and <body> tags.
I am routing a user if the user clicked the button from the dropdown menu but it only redirects me to a blank page.
Picture of button from dropdown:
Picture of the blank page:
Snippet code of dropdown menu:
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->first_name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
#can('manage-agent')
<a class="dropdown-item" href="{{ route('agent.flightManagement') }}">
<i class="fa fa-plane" aria-hidden="true"></i>
Flight Management
</a>
<a class="dropdown-item" href="#">
<i class="fa fa-book" aria-hidden="true"></i>
Booking Management
</a>
<a class="dropdown-item" href="#">
<i class="fa fa-user" aria-hidden="true"></i>
User Management
</a>
<a class="dropdown-item" href="#">
<i class="fa fa-address-book" aria-hidden="true"></i>
Passenger Management
</a>
<hr>
#endcan
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
<i class="fa fa-power-off" aria-hidden="true"></i>
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</div>
</li>
Snippet code of web.php:
Route::namespace('Agent')->middleware('can:manage-agent')->group(function(){
Route::resource('/agent', 'AgentsController');
Route::get('agent/flightManagement', 'AgentsController#flightManagement')->name('agent.flightManagement');
Route::post('/agent/store', 'AgentsController#store')->name('agent.store');
});
Snippet code of flightManagement function inside the AgentsController:
public function flightManagement()
{
return view('agent\flightManagement');
}
I don't know what causes this problem because it only shows a blank page and there is no error even in browser's console but in the laravel.log file it shows this:
[previous exception] [object]
(Symfony\Component\Routing\Exception\RouteNotFoundException(code:
0): Route [flightManagement] not defined. at
C:\xampp\htdocs\ChingChong_Airlines\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php:420)
[stacktrace]
0 C:\xampp\htdocs\ChingChong_Airlines\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(782):
Illuminate\Routing\UrlGenerator->route('flightManagemen...', Array,
true)
1 C:\xampp\htdocs\ChingChong_Airlines\storage\framework\views\8d22c5f09df43b073d10fd0d1dc7f6aa250603dd.php(73):
route('flightManagemen...')
Try to re-create a new view with different name, like helpers-working.php
I am working with the older version of Laravel and I don't which version I am working on as this project was given to me for debugging. I have zero knowledge of Laravel. Doing php artisan --version gave me this as an output in git bash
Following is the code:
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<li class="nav-item nav-profile">
<div class="nav-link">
<div class="user-wrapper">
<div class="text-wrapper">
<p class="profile-name"><?php echo GetUserDetail::get(Session::get('admin_id'),'fullname');?> <span class="status-indicator online"></span></p>
</div>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="dashboard" style="background-color: #518be6 !important; width:250px; color: #fff !important; border-radius: 0px;">
<i class="fas fa-tachometer-alt menu-icon" style="color: #fff"></i>
<span class="menu-title">ड्याशबोर्ड</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="service">
<i class="fas fa-briefcase menu-icon"></i>
<span class="menu-title">सेवाहरू</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="resource">
<i class="fab fa-osi menu-icon"></i>
<span class="menu-title">संसाधन</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="agenda">
<i class="fab fa-forumbee menu-icon"></i>
<span class="menu-title">परियोजना</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="profile">
<i class="fas fa-people-carry menu-icon"></i>
<span class="menu-title">प्रोफाइल</span>
</a>
</li> <li class="nav-item">
<a class="nav-link" href="notice">
<i class="fas fa-info-circle menu-icon"></i>
<span class="menu-title">सूचना तथा जानकारी</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_user">
<i class="fas fa-user-plus menu-icon"></i>
<span class="menu-title">थप प्रयोगकर्ता</span>
</a>
</li>
</ul>
</nav>
I tried keeping / just before href like href="/dashboard". My expected output is http://demo.com/admin/dashboard but when I click on the link it goes like this http://demo.com/dashboard.
I also tried doing href="{{ url('dashboard')}}" which converts my URL to like this:
http://demo.com/admin/%7B%7B%20url('dashboard')%7D%7D
What should be done to fix this?
Your short fix would be this,
href="/admin/dashboard"
The problem was with the way html use href attribute. When you put '/' (forward slash) at the very beginning it starts from the root directory not from the current directory.
However this is a bad practice. You should study routing method and url generation . For large project your url controller will be much easier.
(I don't know your version of laravel. So I provided the link of the latest version. But you can change it from menu.)
I want to make my index page with both guest and auth functions.
When guests visit, they could try logging in; And after login, it will show the user's info such as username.
Route routes/web.php:
Route::get('vendor', function () {
return view('vendor.home');
})->name('vendor')->middleware('web');
in blade template i use Auth::check() to authentication but failed.if i use middleware(['web','auth:vendor']) if guest will redirect to login page
#if(Auth::guest())
<li> <strong><i class="fa fa-user"></i> Login </strong> </li>
<li> <strong>Register</strong> </li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Log Out
</li>
</ul>
</li>
#endif
{{ dd(Auth::check()) }}
Every time I logged in successfully, it will still show login button instead of user name button, after I REFRESH the index page.
this result
try replace Auth:: with \Auth:: or auth()
#if(\Auth::guest())
<li> <strong><i class="fa fa-user"></i> Login </strong> </li>
<li> <strong>Register</strong> </li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ \Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Log Out
</li>
</ul>
</li>
#endif
{{ dd(\Auth::user()) }}
This my answer
#if(Auth::guard('vendor')->check())
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::guard('vendor')->user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Dashboard
</li>
<li>
<a href="{{ route('vendor.logout') }}" >Log Out</a>
</li>
</ul>
</li>
#else
<li> <strong><i class="fa fa-lock"></i> Login </strong> </li>
<li> <strong>Register</strong> </li>
#endif
I am having trouble to adding class "menu-open" and "active" if I use a Multi-level menu.
I succeeded in adding active class in single menu.
Single Menu
<li class="nav-item">
<a href="{{ route('listTemuan') }}" class="nav-link {{ Route::currentRouteNamed('listTemuan') ? 'active' : '' }}">
<i class="fa fa-table nav-icon"></i>
<p>
List Temuan
</p>
</a>
</li>
I don't understand how to make it in Multi-level menu.
This is for my Multi-level menu:
<li class="nav-item has-treeview"> //I want to add class menu-open in here
<a href="#" class="nav-link"> //I want to add class active in here
<i class="fa fa-gear nav-icon"></i>
<p>
Setting
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{ route('UserPekerja') }}" class="nav-link {{ Route::currentRouteNamed('UserPekerja') ? 'active' : '' }}">
<i class="fa fa-circle-o nav-icon"></i>
<p>User Pekerja</p>
</a>
</li>
</ul>
</li>
Use your route name to accomplish it like below code
#if(\Request::route()->getName() == 'route name')
class="nav-item has-treeview open"
#else class="nav-item has-treeview"
#endif
use same segment with appropriate checking
#if(\Request::route()->getName() == 'expected route name')
class="nav-link active"
#else class="nav-link"
#endif