how to show navbar only when i opening special view. example i have create this is app.blade.php
#guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
#endif
#Post
<div>post New</div>
#endPost
#else
#endguest
i want to showing those navbar only if i opening post.blade.php ini my view
Get the route name whois to load post.blade.php this view and then checked if the current route Route::currentRouteName(); match your routes.
//Example
#if('load_view_route_name' == Route::currentRouteName())
//Your Nav or Other elements
#endif
Related
I'm using Laravel 9 for the project. I'm having problem on active menu on current page. Menu become active only when I added the route to href. Active class added automatically on list class.
When I added
{{ route('any-route-name') }}
to my link as below sample
<li class="nav-item">
<a class="nav-link" href="{{ route('any-route-name') }}"> <i class="fa fa-building nav-icon"></i> Companies</a>
</li>
an active class added to list. Did an inspect element, active class added to the list as below sample
<li class="nav-item active">
<a class="nav-link" href="{{ route('any-route-name') }}"> <i class="fa fa-building nav-icon"></i> Companies</a>
</li>
did inspection on view page source but active class not exist. The moment I remove the
{{ route('any-route-name') }}
active class no more added. Can any one explain/assist me on this. I don't have any JS to add active class after page rendered.
is('admin/cities')) ? 'active' : '' }}">
**Approach 2. Starting with the URL**
is('admin/cities*')) ? 'active' : '' }}">
Try this code
<li class="nav-item">
<a class="nav-link #if(Request::segment(1) == 'any-route-name') active #endif" href="{{ route('any-route-name') }}"> <i class="fa fa-building nav-icon"></i> Companies</a>
</li>
Hope this help!
How can I set active selected tab and and also open the sub tab if the page I'm on is a sub page on my sidebar? For example if I open Contractor Association page, the Users tab should expand the highlight Contractor Association tab. Right now every time I open a new page the sidebar is will reset back
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link {{ (request()->is('home')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.home') }}">
<i class="ni ni-tv-2"></i> {{ __('Dashboard') }}
</a>
</li>
<li class="nav-item">
<a class="nav-link {{ (strpos(Route::currentRouteName(), 'dev-admin.home') == 0) ? 'text-primary' : '' }}"
href="#users" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="users">
<i class="fa fa-users"></i>
<span class="nav-link-text">{{ __('Users') }}</span>
</a>
<div class="collapse {{ (request()->is('dev-admin/developer-admins*') ? 'show' : '' }}"
id="users">
<ul class="nav nav-sm flex-column">
<li class="nav-item">
<a class="nav-link {{ (request()->is('developer-admins')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a>
<a class="nav-link {{ (request()->is('dev-admin/defect-types*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.clerk-of-works.index') }}">
{{ __('Clerks of Work') }}
</a>
<a class="nav-link {{ (request()->is('developer-admins')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-contractor-associations.index') }}">
{{ __('Contractor Association') }}
</a>
</li>
</ul>
</div>
</li>
</ul>
you can write the code like in side bar all the section
<li class="#if(Route::is('developer-admins')) {{ 'active' }} #endif"
<a href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a></li>
and also you can use like
<li class="{{ set_active(['login*']) }}">
Login
</li>
<li class="{{ set_active(['register*']) }}">
Signup
</li>
I am using bellow code for many project which is used into production ready web app and api.
Add bellow line into html class attributes for highlighting active route.
{{ request()->is('dashboard/report') ? 'active' : '' }}
This is really handy for active class.
So I fix it and also show/open tab for selected page by doing something like this, it appears the url I gave is incomplete, thanks everyone for the suggestion..
<div class="collapse {{ (request()->is('dev-admin/developer-admins*') || request()->is('dev-admin/clerks-of-works*') || request()->is('dev-admin/developer-contractor-associations*')) ? 'show' : '' }}"
id="users">
<ul class="nav nav-sm flex-column">
<li class="nav-item">
<a class="nav-link {{ (request()->is('dev-admin/developer-admins*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a>
<a class="nav-link {{ (request()->is('dev-admin/clerks-of-works*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.clerk-of-works.index') }}">
{{ __('Clerks of Work') }}
</a>
</li>
</ul>
</div>
I can not get out of my application, I'm using the auth out of box login for laravel 5, but when I get out of my account, I'm not successful.
EDIT: the problem is that dropdown menu does not open for me to logout.
Can someone help me ?
this is my app.blade.php ->
#guest
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endguest
#theFlash So CSS is setting the logout button to style="display: none" you need to set this to either display: block;, display: inline-block; or display: inline; to get it to show up. At the moment it's hidden by CSS so you can't click it...
Adding app.js file helped me to open the dropdown
//app.blade.php
<script src="{{ asset('js/app.js') }}"></script>
I am new to laravel5.4. By using this url i am trying to make user management. After installing everything i got below error. Please help this out to fix this error
(3/3) ErrorException
Call to undefined method Illuminate\Database\Query\Builder::hasRole() (View: /var/www/html/laravel5/resources/views/layouts/app.blade.php) (View: /var/www/html/laravel5/resources/views/layouts/app.blade.php)
My layout app.blade.php is as below
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
#if (Auth::guest())
<li>Login</li>
<li>Register</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>
#role('Admin') {{-- Laravel-permission blade helper --}}
<i class="fa fa-btn fa-unlock"></i>Admin
#endrole
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endif
</ul>
I have 2 users which is seller and user. Login function for both is fine but when I login to seller there is no logout button.
Route:
Route::post('/logout', 'Auth\PsController#logout');
psblade:
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
#if (Auth::guest())
<li>Loginnn</li>
<li>Registerr</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>
<a href="{{ route('/logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endif