I already tried this 2 types of code which is {{Request::is('residential') ? 'active' : ''}} and {{ 'contractor' == request()->path() ? 'active' : '' }} But still nothing is happened. This is my whole code for sidebar.blade.php
<div id="sidebar-nav" class="sidebar">
<div class="sidebar-scroll">
<nav>
<ul class="nav">
#if(auth()->user()->role == 'admin')
<li class="{{Request::is('residential') ? 'active' : ''}}">
<i class="lnr lnr-apartment"></i><span>Residence</span>
</li>
<li class="{{ 'contractor' == request()->path() ? 'active' : '' }}">
<i class="lnr lnr-magic-wand"></i><span>Contractor</span>
</li>
#endif
</ul>
</nav>
</div>
</div>
web.php
Route::group(['middleware' => 'auth','checkRole:admin'], function () {
Route::get('/residential','ResidentialController#index');
Route::get('/contractor', 'ContractorController#index')->name('contractor')
}
What I suppose to do? I hope someone can help me to figure this out.
Related
Asking for your help please. I want to show different Applicants on different tabs in my edit.blade.php, I just wondering how can I do that? Please help me.
Controller.php
public function edit($id)
{
$applications = application::where('id', $id)->first();
return view('user.application.edit', compact('applications'));
}
edit.blade.php
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link {{ request()->is('applicant1') ? 'active' : null }}" href="{{ url('applicant1') }}" role="tab">Main Applicant</a>
</li>
<li class="nav-item">
<a class="nav-link {{ request()->is('applicant2') ? 'active' : null }}" href="{{ url('applicant2') }}" role="tab">Applicant 2</a>
</li>
<li class="nav-item">
<a class="nav-link {{ request()->is('applicant3') ? 'active' : null }}" href="{{ url('applicant3') }}" role="tab">Applicant 3</a>
</li>
</ul><!-- Tab panes -->
<div class="tab-pane {{ request()->is('applicant1') ? 'active' : null }}" id="{{ url('applicant1') }}" role="tabpanel">
//FORM HERE
</div>
web.php I was trying different approaches on routes too.
Route::get('applicant1', 'ApplicationController#edit')->name('application.edit');
Route::get ('/applicant2', function () {
return view('application.edit');});
Route::get ('/applicant3', function () {
return view('application.edit');});
Please help me.
Why don't you use a foreach for each applicant element?
In your controller
public function edit($id)
{
$applications = application::all();
return view('user.application.edit', compact('applications'));
}
I your view:
<ul class="nav nav-tabs" role="tablist">
#foreach($applications as $applicant)
<li class="nav-item">
<a class="nav-link {{ request('id') == $applicant->id ? 'active' : ''}}" href="{{ route('application.edit', $applicant->id) }}" role="tab">Main Applicant</a>
</li>
#endforeach
</ul>
<div class="tab-content" id="myTabContent">
#foreach($applications as $applicant)
// the rest of panels
<div class="tab-pane fade show {{ request('id') == $applicant->id ? 'active' : '' }}" id="tab-{{ $loop->iteration }}" role="tabpanel"></div>
#endforeach
</div>
In your routes.php
Route::get('applicants/{id}', 'ApplicationController#edit')->name('application.edit');
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>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
i am beginner in programming and in laravel, and i have some issue about my code/project.
I want a condition where my main web menu can only be accessed by auth user, but i have an error when make condition in the code.
Please help me fix this problem
*ps sory for bad english
here the views
<!DOCTYPE html>
<html lang="en">
<head>
<title>DOKO MOTOR</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="{{url('/')}}/css/lwd.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div id="top-header" style="background:#FFF;height: 100px;"s>
<div id="header" class="hidden-sm hidden-xs">
<img src="{{url('/')}}/img/logo.png" height="90px" style="position: absolute;">
<div class="bendera"></div>
<div class="hotline pull-right">
<div class="left"><i class="glyphicon glyphicon-earphone" style="
font-size: 50px; color:red;
"></i></div>
<div class="right">
<div class="r-top">hotline :</div>
<div class="r-bot">0896 5200 6229</div>
</div>
<div class="break"></div>
</div><!-- /.hotline -->
<div class="top-wel pull-right">Selamat datang di website kami, Jumat, 11 Mei 2018 </div>
</div><!-- /#header -->
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="{{ url("") }}">DOKO MOTOR</a>
</div>
<ul class="nav navbar-nav">
<!-- #if(Auth::user()) -->
#if(Auth::user())
<li class="{{ request()->is('book') ? 'active' : '' }}"><span class="glyphicon glyphicon-wrench"></span> Book Service</li>
<!-- #endif -->
<li class="{{ request()->is('services') ? 'active' : '' }}"><span class="glyphicon glyphicon-hourglass"></span> Antrian Service</li>
<li class="{{ request()->is('contact') ? 'active' : '' }}"><span class="glyphicon glyphicon-user"></span> Kontak</li>
<li class="{{ request()->is('tentang') ? 'active' : '' }}"><span class="glyphicon glyphicon-earphone"></span> Tentang</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<!-- #if(Auth::user()) -->
<li><a href="{{URL::to('/logout')}}">
<span style="color: blue"> {{ ucwords(Auth::user()->name) }}</span> <span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
<!-- #else -->
#else
<li><span class="glyphicon glyphicon-user"></span> Daftar</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
<!-- #endif -->
#endif
</ul>
</div>
</nav>
<div class="container">
#yield('content')
</div>
<div id="footer">
<div class="row">
<div class="col-md-12">
<div class="copy">Copyright © 2018 - All rights reserved.</div>
</div>
</div><!-- /.row -->
</div>
</body>
</html>
here the route
Route::get('/signin', function() {
return view('login');
});
Route::get('/register/{date?}', function($date = null) {
return view('register',['date',$date]);
});
Route::post('/register_action/{date?}','RegisterController#store');
Route::post('/login_check','RegisterController#login');
Route::get('logout', function() {
Auth::logout();
return Redirect::to('');
})->middleware("auth");
Route::get('/', function(){
if( auth()->check() ){
return Redirect::to('/');
}else{
return Redirect::to('/auth');
}
});
Route::get('/', 'HomeController#index');
Route::get('/contact','ContactController#index');
Route::get('/tentang','TentangController#index');
Route::get('/book/{date?}', 'ServisController#book');
Route::get('/services/{add?}', 'ServisController#services');
Route::post('/submit_book', 'ServisController#submit_book');
Route::post('/update_service', 'ServisController#update_service');
Route::post('/delete_service', 'ServisController#delete_service');
error message
I'll appreciate anything would help me
Kindly regards
Try changing the way you structure your html:
#if(Auth::user())
<ul class="nav navbar-nav">
<li class="{{ request()->is('book') ? 'active' : '' }}"><span class="glyphicon glyphicon-wrench"></span> Book Service</li>
<li class="{{ request()->is('services') ? 'active' : '' }}"><span class="glyphicon glyphicon-hourglass"></span> Antrian Service</li>
<li class="{{ request()->is('contact') ? 'active' : '' }}"><span class="glyphicon glyphicon-user"></span> Kontak</li>
<li class="{{ request()->is('tentang') ? 'active' : '' }}"><span class="glyphicon glyphicon-earphone"></span> Tentang</li>
</ul>
#endif
<ul class="nav navbar-nav navbar-right">
#if(Auth::user())
<li><a href="{{URL::to('/logout')}}">
<span style="color: blue"> {{ ucwords(Auth::user()->name) }}</span> <span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
#else
<li><span class="glyphicon glyphicon-user"></span> Daftar</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
#endif
</ul>
The way you write your HTML must make sense after the if statements, to visualise this try removing the code that a situation would create, so if the user isn't there remove that code and see what you are left with, at the moment you would have HTML that wouldn't make sense and the browser wouldn't be able to present it in the way you would like
My HTML code is
<div id="sidebar"><i class="icon icon-home"></i>Dashboard
<ul>
<li class="active"><i class="icon icon-home"></i> <span>Scam Type</span> </li>
<li> <i class="icon icon-signal"></i> <span>Scam Database</span> </li>
<li> <i class="icon icon-inbox"></i> <span>Scam Story</span> </li>
<li><i class="icon icon-th"></i> <span>Keyword</span></li>
<li><i class="icon icon-th"></i> <span>Category</span></li>
<li><i class="icon icon-th"></i> <span>Sub Category</span></li>
</ul>
</div>
Here i gave li class active as like in bootstrap and its not working, but i don't know how to give in laravel and i am very beginner of laravel, so please avoid minus votes and give me the right solution for it.. How Should i change my code to get li class active dynamically?
You can use ternary operator. For example, you can check URI for the current route:
<li{{ request()->is('scam-types') ? ' class="active"' : '' }}>
You can also use * as wildcard:
<li{{ request()->is('scam-type-number-*') ? ' class="active"' : '' }}>
Or you can check route name:
<li{{ request()->route()->getName() === 'ScamType.index' ? ' class="active"' : '' }}>
Try Below Code to write each li tag for check some text in URL
if (strpos($_SERVER['REQUEST_URI'], "ScamType") !== false){
echo "active";
}
Write above code in class.
Ex.
<li class="{{ if (strpos($_SERVER['REQUEST_URI'], "ScamType") !== false){ echo "active"; } }}"><i class="icon icon-home"></i> <span>Scam Type</span> </li>
From above answer I have try and doesnt work because class="active" must be class=active
<li><a class="{{ request()->routeIs('about.index*') ? 'active-menu' : '' }}" href="{{route('about.index')}}"><i class="fa fa-desktop"></i> About</a></li>
routeIs('Route_Name*') ? 'active-menu' : '' }}">
In Route Name just write Route name defined in Routes
Is there a way to customize the paginator view in Laravel 5.1.
I want to add a first and last link in addition to the out of the box previous and next links.
I want to change the previous and next links to display icons instead of text but display text for screen readers.
I want to limit the number of page links to display only 5.
Below is what I'm trying to achieve.
<ul class="pagination no-margin pull-right">
<li class="disabled">
First
</li>
<li class="disabled">
<a href="#">
<span class="sr-only">Previous</span>
<i class="fa fa-caret-left" aria-hidden="true"></i>
</a>
</li>
<li class="active">
1
</li>
<li class="">
2
</li>
<li class="">
3
</li>
<li class="">
4
</li>
<li class="">
5
</li>
<li>
<a href="#">
<span class="sr-only">Next</span>
<i class="fa fa-caret-right" aria-hidden="true"></i>
</a>
</li>
<li >
Last
</li>
</ul>
In instead of
$users->render()
use
#include('pagination', ['paginator' => $users])
create pagination.blade in views directory
add this code in pagination file
#if ($paginator->lastPage() > 1)
<ul class="pagination">
<li class="{{ ($paginator->currentPage() == 1) ? ' disabled' : '' }}">
Previous
</li>
#for ($i = 1; $i <= $paginator->lastPage(); $i++)
<li class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }}">
{{ $i }}
</li>
#endfor
<li class="{{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }}">
<a href="{{ $paginator->url($paginator->currentPage()+1) }}" >Next</a>
</li>
</ul>
#endif
you can add your style in this file
get the last page $paginator->lastPage() and first page is 1
You can modify this file for customizing the paginator styling
\vendor\laravel\framework\src\Illuminate\Pagination\BootstrapThreePresenter.php