I am a beginner at laravel and I have Hidden sidebar menu from users it's successfully working but when logout from admin then I face error how to fix it thanks. please see error https://flareapp.io/share/NPL9bz7w
Html view
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview"
role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<!--Admin sidebar menu -->
#if(Auth::user()->type == "admin")
<li class="nav-item">
<a href="{{url('admin')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Users Permission</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('manage_users')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Manage Users</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('register')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p> User Register</p>
</a>
</li>
<!-- end Admin sidebar menu -->
<!-- User sidebar menu -->
#else
<li class="nav-item">
<a href="{{url('viewprofile')}}" class="nav-link">
<i class="fas fa-user"> </i>
<p>View Profile</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('DashBoard')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Chat Room</p>
</a>
</li>
#endif
</ul>
</nav>
<!-- /.sidebar-menu -->
The problem is, you are checking #if(Auth::user()->type == "admin") for check the logged in admin. If the admin is logged out then there is no Auth::user(). I think this is the problem you are facing. So change the condition like this
#if(Auth::check() && Auth::user()->type == "admin")
// Admin menu bar
#elseif (Auth::check())
// User menu bar
#endif
I think this will solve the issue.
Since the user is logged out, the Auth::user() is null.
Because of which, when you try to get its type, it is throwing
Trying to get property 'type' of non-object
You need to check whether the user is logged in, and then check its type.
#if(Auth::check() && Auth::user()->type == "admin")
Auth::check() will return true if the user is logged in
first check if user logged in then check that if user is admin or not:
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview"
role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<!--Admin sidebar menu -->
#auth
#if(Auth::user()->type == "admin")
<li class="nav-item">
<a href="{{url('admin')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Users Permission</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('manage_users')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Manage Users</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('register')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p> User Register</p>
</a>
</li>
<!-- end Admin sidebar menu -->
<!-- User sidebar menu -->
#else
<li class="nav-item">
<a href="{{url('viewprofile')}}" class="nav-link">
<i class="fas fa-user"> </i>
<p>View Profile</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('DashBoard')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Chat Room</p>
</a>
</li>
#endif
#endauth
</ul>
use isset method
#if(isset(Auth::user()->type) && Auth::user()->type== "admin")
you can also use Auth::check()
#if(Auth::check() && Auth::user()->type== "admin")
Related
I have a problem when I use the following code for adding and displaying:
<a href="javascript:void(0)" data-toggle="modal" data-target="#modalYear">
<span class="sub-item">Add year</span>
</a>
<a href="javascript:void(0)" data-toggle="modal" data-target="#ListYear">
<span class="sub-item">Listyear</span>
</a>
Nothing gets blocked but the problem comes when I want to use the edit option the admin menu stops scrolling, this is where the problem starts and also when I use this :
<a href="javascript:void(0)" wire:click="ShowReportModal('add')">
span class="sub-item">Add Year</span>
</a>
the modal will show up but when I close it the admin menu stops scrolling.
After so many tries I figured out that the problem is using wire:click to call the modal for adding, editing and displaying.
this is my component:
public function ShowReportModal($action)
{
if($action == 'add')
{
$this->dispatchBrowserEvent('ModalYearVisible') ;
}
else{
$this->dispatchBrowserEvent('ModalListVisible') ;
}
}
Here is the admin menu code:
<li class="nav-item">
<a data-toggle="collapse" href="#annee">
<i class="far fa-calendar-alt"></i>
<p>Scholar year</p>
<span class="caret"></span>
</a>
<div class="collapse" id="annee">
<ul class="nav nav-collapse">
<li>
<a href="javascript:void(0)" wire:click="ShowReportModal('add')">
<span class="sub-item">Add year</span>
</a>
</a>
</li>
<li>
<a href="javascript:void(0)" wire:click="ShowReportModal('list')">
<span class="sub-item">Years List</span>
</a>
</li>
</ul>
</div>
</li>
Any help would be appreciated and also why is this happening?
I have a navbar and I have 2 elements outside the login option, the thing is that I need that a certain element stays with a certain role and when I'm not logged in...
Here is my code
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#services"><i class="fa fa-search"></i> Buscar</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">Explorar cursos</a>
</li>
#if (Route::has('login'))
#auth
#role('Alumno')
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">Explorar cursos</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="{{route('miscursos')}}"> Mis cursos</a>
</li>
#endrole
#role('Administrador')
<li class="nav-item dropdown">
<a class="nav-link" href="{{ route('home') }}" >
{{ __('Tablero')}}
</a>
</li>
#endrole
The second element on the list is the one I'm having problem with because I want it when I'm browsing in the page but NOT logged in and I need when I'm logged in with an 'Alumno' role
The thing is that I don't wanna see it when I'm logged in as an administrator
You can use :
Auth::guest() for conditional when user it not logged in. So if I am getting it right, in your second list element :
<?php
#if(Auth::guest() || Auth::user()->role != 'Administrator)
// Only visible if user is NOT logged in OR logged in but not an administrator
#endif
I want to set m-menu__item--open class on parent menu <li> and m-menu__item--active class on sub-menu item <li> in my Laravel bade based on current page. Below is the HTML extracted from the bade template.
<li class="m-menu__item m-menu__item--open" aria-haspopup="true" m-menu-submenu-toggle="hover">
<a href="javascript:;" class="m-menu__link m-menu__toggle">
<i class="m-menu__link-icon flaticon-layers"></i>
<span class="m-menu__link-text">FAQ</span>
<i class="m-menu__ver-arrow la la-angle-right"></i>
</a>
<div class="m-menu__submenu " m-hidden-height="840">
<span class="m-menu__arrow"></span>
<ul class="m-menu__subnav">
<li class="m-menu__item m-menu__item--active" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/1" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">English</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/2" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Korean</span>
</a>
</li>
<li class="m-menu__item m-menu__item" aria-haspopup="true">
<a href="{{ url('/') }}/admin/faq/list/3" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--dot">
<span></span>
</i>
<span class="m-menu__link-text">Chinese</span>
</a>
</li>
</ul>
</div>
</li>
as I understand, you want to change your menu classes by the current url..
laravel has is() method in Request class. You may want to use it.
class="{{Request::is('category/products') ? 'm-menu__item--active' : 'm-menu__item--open'}}"
if your current url base-url/category/products then you're gonna get the 'm-menu__item--active' class
I have a application with extends a view with name "notification". How you can see in the picture.
That fragment is just a list, don't extends anything, How I pass a variable to that list? Something fixed. Any suggestion?
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="livicon" data-name="bell" data-loop="true" data-color="#e9573f"
data-hovercolor="#e9573f" data-size="28"></i>
<span class="label label-warning">7</span>
</a>
<ul class=" notifications dropdown-menu drop_notify">
<li class="dropdown-title">Você tem novas notificações</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
#foreach($notificacao as $value)
<li>
<i class="livicon default" data-n="asterisk" data-s="20" data-c="white"
data-hc="white"></i>
Você tem novas perguntas
<small class="pull-right">
<span class="livicon paddingright_10" data-n="timer" data-s="10"></span>
{{$value->created_at->diffForHumans()}}
</small>
</li>
#endforeach
</ul>
</li>
<li class="footer">
View all
</li>
</ul>
</li>
I have the top-bar nav all setup and the dropdowns are displaying as expected. However, when I click on a dropdown link, the dropdown just disappears. The page does not advance to the URI as expected.
I'm stumped...
<section class="top-bar-section second-row">
<ul>
<li class="active"><i class="fa fa-exclamation-triangle"></i><span> Alert Central</span></li>
<li class="has-dropdown">
<i class="fa fa-bar-chart"></i><span> Analytics</span>
<ul class="dropdown">
<li>System Status</li>
<li>My Use</li>
<li>My User's Use</li>
<li>Account Information</li>
</ul>
</li>
<li class="has-dropdown">
<i class="fa fa-magic"></i><span> Filter Management</span>
<ul class="dropdown">
<li>Keywords</li>
<li>Categories</li>
<li>Locations</li>
</ul>
</li>
<li class="has-dropdown">
<i class="fa fa-users"></i><span> User Management</span>
<ul class="dropdown">
<li>Users</li>
<li>Roles</li>
</ul>
</li>
</ul>
</section>
Did you try to add data-topbar in <section> tag ?
<section data-topbar class="top-bar-section second-row">