I'm trying to display some results on a table based on few dropdown which is used for displaying different results, I choose the parameter followed the date. Unfortunately if I'm not mistaken it is illegal to have two ids on a tbody, as seen my code only takes into consideration of the date and not the parameter selected, so is there any alternative solution to what I'm trying to do?
#extends('app')
#section('header')
<link href="css/reports.css" rel="stylesheet">
#stop
#section('content')
<h1 class="page-header">Reports Archive</h1>
<div class="dropdown">
<a style="font-weight:bold" id="drop5" href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" role="button" aria-expanded="false">
Zone Options:
<span class="caret"></span>
</a>
<ul id="menu2" class="dropdown-menu" role="menu" aria-labelledby="drop5">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<li role="presentation" class="{{ $count == 0 ? 'active' : '' }}">
<a role="menuitem" tabindex="-1" href="#" data-target="#zone{{ $zone->id }}"> {{ $zone->zone_name }}</a></li>
<?php $count++; ?>
#endforeach
</ul>
</div>
<div role="tabpanel">
<!-- hide the below links-->
<ul class="nav nav-tabs" style="display:none;" role="tablist" id="myTab">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<li role="presentation" class="{{ $count == 0 ? 'active' : '' }}">{{ $zone->zone_name }}</li>
<?php $count++; ?>
#endforeach
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<div role="tabpanel" class="tab-pane fade in {{ $count == 0 ? 'active' : '' }}" id="zone{{ $zone->id }}">
<div class="col-md-12">
<h2> {{ $zone->zone_name }} </h2>
<table class="table table-responsive table-hover table-bordered">
<thead>
<tr>
<th style="vertical-align:middle">#</th>
<th>
<div class="dropdown">
<a style="font-weight:bold" id="drop5" href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" role="button" aria-expanded="false">
Parameter Name:
<span class="caret"></span>
</a>
<ul id="menu2" class="dropdown-menu" role="menu" aria-labelledby="drop5">
#foreach ($zone->parameter as $param)
<li role="presentation">
<a class="btn btn-link" data-collapse-group="filters" data-target="#{{ $param->id }}" data-toggle="collapse">{{ $param->parameter_name }}</a></li>
#endforeach
</ul>
</div>
</th>
<th style="vertical-align:middle">Reading Value</th>
<th style="vertical-align:middle">User</th>
<th style="vertical-align:middle">Status</th>
<th style="vertical-align:middle">
<div class="dropdown" style="position:relative">
<a style="font-weight:bold" href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Timestamp
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<?php $validate = "default" ?>
<?php $records = App\Reading::sort()->get() ?>
#foreach ($records as $record)
#if ($record->created_at->year != $validate)
<li>
<a class="trigger right-caret">
{{ $record->created_at->year }}
</a>
<ul class="dropdown-menu sub-menu">
<li>January</li>
<li>February</li>
<li>March</li>
<li>April</li>
<li>May</li>
<li>June</li>
<li>July</li>
<li>August</li>
<li>September</li>
<li>October</li>
<li>November</li>
<li>December</li>
</ul>
</li>
<?php $validate = $record->created_at->year ?>
#endif
#endforeach
</ul>
</div>
</th>
</tr>
</thead>
<?php $validate = "default" ?>
#foreach ($records as $record)
#if ($record->created_at->year != $validate)
<?php $month = 1; ?>
#while ($month != 13)
#foreach ($parameters as $param)
<?php $index = 1; ?>
#if ($param->zone_id == $zone->id)
<tbody id="{{ $record->created_at->year }}-{{ $month }}" class="collapse">
#foreach ($readings as $reading)
#if ($reading->parameter_id == $param->id)
#if ($reading->created_at->year == $record->created_at->year)
#if ($reading->created_at->month == $month)
<tr>
<td>{{ $index }}</td>
<td>{{ $reading->parameter->parameter_name }} </td>
<td>{{ $reading->reading_value }} </td>
<td>{{ $reading->user->name }} </td>
<td>{{ $reading->parameter->threshold->getStatus($reading->reading_value) }} </td>
<td>{{ $reading->created_at }} </td>
</tr>
<?php $index++; ?>
#endif
#endif
#endif
#endforeach
#endif
</tbody>
</div>
#endforeach
<?php $month++; ?>
#endwhile
<?php $validate = $record->created_at->year ?>
#endif
#endforeach
</div>
</table>
</div>
</div>
<?php $count++; ?>
#endforeach
</div>
</div>
#stop
#section('scripts')
<script>
$(function(){
$(".dropdown-menu > li > a.trigger").on("click",function(e){
var current=$(this).next();
var grandparent=$(this).parent().parent();
if($(this).hasClass('left-caret')||$(this).hasClass('right-caret'))
$(this).toggleClass('right-caret left-caret');
grandparent.find('.left-caret').not(this).toggleClass('right-caret left-caret');
grandparent.find(".sub-menu:visible").not(current).hide();
current.toggle();
e.stopPropagation();
});
$(".dropdown-menu > li > a:not(.trigger)").on("click",function(){
var root=$(this).closest('.dropdown');
root.find('.left-caret').toggleClass('right-caret left-caret');
root.find('.sub-menu:visible').hide();
});
});
</script>
#stop
It is illegal to have two ids on the same HTML element, as in this example
<div id="id1" id="id2"> <!-- Here be dragons -->
You can skirt this by just having a delimeter in a single id:
<div id="id1--id2">
Or, you can use arbitrary data attributes:
<div id="" data-date="2015-10-14" data-parameter="zone_id">
Since you're using jQuery, here is a question that specifically asks about how to retrieve a data attribute.
Related
I'm trying to implement onEachSide(1) into custom pagination in bootstrap 5, but can't understand how should I implement this.
Below is my code reference.
DistributorController.php
public function distributorList(Request $request)
{
$input = $request->all();
$search = isset($input['search']) ? $input['search'] : '';
$list = $this->distributorRepository->allList($input);
return view('admin.distributor.distributor')->with(['data'=>$list,'filter' => $search]);
}
allList method inside distributorRepository.php
public function allList($input)
{
$res = $this->makeModel();
if (isset($input['search'])) {
$search = $input['search'];
$res = $res->where(function($query) use($search) {
$query->where('distributorId', 'LIKE', "%{$search}%" )
->orWhere ( 'name', 'LIKE', "%{$search}%" )
->orWhere ( 'mobile_no', 'LIKE', "%{$search}%" )
->orWhere ( 'email', 'LIKE', "%{$search}%" );
});
}
$res = $res->paginate(1)->withQueryString();
return $res;
}
custom-pagination.blade.php
#if ($paginator->hasPages())
<div class="position-absolute start-0">
<select class="select2 px-2 py-2" name="limit" id="limit">
<option value="15">15</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="all">All</option>
</select>
</div>
<div class="position-absolute end-0 d-flex">
<div class="px-2 py-2">
Showing {{ $paginator->firstItem() }}
to {{ $paginator->lastItem() }}
of {{ $paginator->total() }} results
</div>
<nav>
<ul class="pagination">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.previous')">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li>
#else
<li class="page-item">
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev"
aria-label="#lang('pagination.previous')">Previous</a>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if (is_string($element))
<li class="page-item disabled" aria-disabled="true">
<span>{{ $element }}</span>
</li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="page-item active" aria-current="page">
<a class="page-link" href="{{ $url }}">{{ $page }}
<span class="sr-only">(current)</span>
</a>
</li>
#else
<li class="page-item">
<a class="page-link" href="{{ $url }}">{{ $page }}</a>
</li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="page-item">
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next"
aria-label="#lang('pagination.next')">Next</a>
</li>
#else
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.next')">
<a class="page-link" href="#">Next</a>
</li>
#endif
</ul>
</nav>
</div>
#endif
But i want like this :-
Previous 1 2 ... 9 10 11 ... 19 20 Next
im new for laravel but i think you can use this
#if ($paginator->hasPages())
<ul class="pagination pagination">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="disabled"><span>«</span></li>
#else
<li>«</li>
#endif
#if($paginator->currentPage() > 3)
<li class="hidden-xs">1</li>
#endif
#if($paginator->currentPage() > 4)
<li><span>...</span></li>
#endif
#foreach(range(1, $paginator->lastPage()) as $i)
#if($i >= $paginator->currentPage() - 1 && $i <= $paginator->currentPage() + 1)
#if ($i == $paginator->currentPage())
<li class="active"><span>{{ $i }}</span></li>
#else
<li>{{ $i }}</li>
#endif
#endif
#endforeach
#if($paginator->currentPage() < $paginator->lastPage() - 3)
<li><span>...</span></li>
#endif
#if($paginator->currentPage() < $paginator->lastPage() - 2)
<li class="hidden-xs">{{ $paginator->lastPage() }}</li>
#endif
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li>»</li>
#else
<li class="disabled"><span>»</span></li>
#endif
</ul>#endif
onEachSide just sets the value to be used when creating pages, so you can modify the value before you pass the results to the view.
$res = $res->paginate(1)->withQueryString();
$res->onEachSide(1);
I need to use pagination on a laravel blade, but from the controller comes another variable that does not pass pagination, how can I solve it?
<div class="main-content">
<div class="breadcrumb">
<h1>Página de Cliente</h1>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="card user-profile o-hidden mb-4">
<div class="user-info"><img class="profile-picture avatar-lg mb-2" alt="" />
<p class="m-0 text-24">{{ $customer->name }}</p>
<p class="text-muted m-0">{{ $customer->email }}</p>
</div>
<div class="card-body">
<ul class="nav nav-tabs profile-nav mb-4" id="profileTab" role="tablist">
<li class="nav-item"><a class="nav-link active" id="timeline-tab" data-toggle="tab" href="#timeline" role="tab" aria-controls="timeline" aria-selected="false">Propostas</a></li>
<li class="nav-item"><a class="nav-link" id="about-tab" data-toggle="tab" href="#about" role="tab" aria-controls="about" aria-selected="true">#</a></li>
<li class="nav-item"><a class="nav-link" id="friends-tab" data-toggle="tab" href="#friends" role="tab" aria-controls="friends" aria-selected="false">#</a></li>
<li class="nav-item"><a class="nav-link" id="photos-tab" data-toggle="tab" href="#photos" role="tab" aria-controls="photos" aria-selected="false">#</a></li>
</ul>
<div class="tab-content" id="profileTabContent">
<div class="tab-pane fade active show" id="timeline" role="tabpanel" aria-labelledby="timeline-tab">
<div class="row mb-4">
<div class="col-md-12 mb-3">
<div class="card text-left">
<div class="card-body">
<h4 class="card-title mb-3">Lista de Propostas</h4>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Data</th>
<th scope="col">Vendedor</th>
<th scope="col">Produto</th>
<th scope="col">Preço</th>
<th scope="col">Produção</th>
</tr>
</thead>
#foreach($proposals as $proposal)
<tbody>
<tr>
<th scope="row"> {{ $proposal->id_proposal }} </th>
<td> {{ $proposal->date }} </td>
<td> {{$proposal->users()->first()->name }} </td>
<td>
#foreach($proposal->proposed_phases()->get() as $proposedphase)
<p>{{ $proposedphase->features()->first()->name }}</p>
#endforeach
</td>
<td>
#foreach($proposal->proposed_phases()->get() as $proposedphase)
<p>{{ $proposedphase->amount }}€</p>
#endforeach
</td>
#if($proposal->id_production == null)
<td><span class="badge badge-danger">Produção</span></td>
#else
<td><span class="badge badge-success">Produção</span></td>
#endif
#if($proposal->id_production == null)
<td>
<a href="{{ URL::route('new.production', array('id_proposal'=>$proposal->id_proposal)) }}" class="text-success mr-2">
<button class="nav-icon i-Add font-weight-bold btn btn-success m-0" type="button" data-toggle="tooltip" data-placement="top" title="Criar Produção"></button>
</a>
</td>
#else
<td>
<a href="{{ URL::route('new.label', array('id_proposal'=>$proposal->id_proposal)) }}" class="text-success mr-2">
<button class="nav-icon i-Add font-weight-bold btn btn-warning m-0" type="button" data-toggle="tooltip" data-placement="top" title="Criar Etiquetas"></button>
</a>
</td>
#endif
</tr>
</tbody>
#endforeach
</table>
{{-- Pagination --}}
<div class="d-flex justify-content-center">
{!! $proposals->links() !!}
</div>
</div>
</div>
</div>
</div>
CONTROLLER
public function PageCustomer(Request $request)
{
$data = $request->all();
$customer = customer::where('id_customer', $data['id_customer'])->first();
$proposals = proposal::where('id_customer', $customer['id_customer'])->paginate(5);
return view('admin.customer.page_customer', compact('customer', 'proposals'));
}
the variable that does not pass to the second page is $customer
I tried to pass an array with the values of name and email, but it didn't work. how can i resolve this situation?
Use appends on Paginator :
{!! $proposals->appends(['customer' => $customer])->links() !!}
As of Laravel 7, you can call the withQueryString() method on your Paginator instance :
{!! $proposals->withQueryString()->links() !!}
withQueryString() method appends all current query string values to the pagination links.
In my accordion I am showing the parent items. Which I am getting by using getItems() method. It is being linked to every item. And every parent item has some child items. Which I am getting using ($item->children as $child) And when clicks any parent item, the child items of that parent item should be visible from drop down.
The problem is whenever I click any parent item, every child item is being shown in the drop down. But I want only the child item of the parent item to be shown. It would be nice If someone can help me out. Thanks in advance.
This is my blade file code.
<div class="container my-4">
<div class="accordion md-accordion" id="accordionEx" role="tablist" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" id="headingTwo2">
#foreach(getItems() as $item)
<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx" href="#collapseTwo2"
aria-expanded="false" aria-controls="collapseTwo2">
<h5 class="mb-0">
{{ $item->name }} <i class="fas fa-angle-down rotate-icon"></i>
</h5>
</a>
<div id="collapseTwo2" class="collapse" role="tabpanel" aria-labelledby="headingTwo2"
data-parent="#accordionEx">
<div class="card-body">
#foreach ($item->children as $child)
<a href="{{ route('category.island.list') }}?category={{ $child->id }}"
class="dropdown-item" data-id="{{ $child->id }}" data-name="{{ $child->name }}">
<span>{{ $child->name }}</span>
</a>
#endforeach
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
This is normal, because they all have the same href here:
<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx" href="#collapseTwo2"
aria-expanded="false" aria-controls="collapseTwo2">
and they all have make reference to the same "id" in this div:
<div id="collapseTwo2" class="collapse" role="tabpanel" aria-labelledby="headingTwo2"
data-parent="#accordionEx">
So just add a variable in your foreach as a "count" that will increase foreach loop and you just add that into your href and Id with twig and that is fine :)
Twig way:
Out of 1st foreach : TWIG : {% set count = 0 %} PHP : <?php $count = 0; ?>
In your 1st foreach at the end: TWIG : {% set count = count + 1 %} PHP : <?php $a++; ?>
As follow:
<div class="container my-4">
<div class="accordion md-accordion" id="accordionEx" role="tablist" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" id="headingTwo2">
<?php $count = 0; ?>
#foreach(getItems() as $item)
<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx" href="#collapseTwo2{{ $count }}"
aria-expanded="false" aria-controls="collapseTwo2{{ $count }}">
<h5 class="mb-0">
{{ $item->name }} <i class="fas fa-angle-down rotate-icon"></i>
</h5>
</a>
<div id="collapseTwo2{{ $count }}" class="collapse" role="tabpanel" aria-labelledby="headingTwo2"
data-parent="#accordionEx">
<div class="card-body">
#foreach ($item->children as $child)
<a href="{{ route('category.island.list') }}?category={{ $child->id }}"
class="dropdown-item" data-id="{{ $child->id }}" data-name="{{ $child->name }}">
<span>{{ $child->name }}</span>
</a>
#endforeach
</div>
</div>
<?php $count++; ?>
#endforeach
</div>
</div>
</div>
</div>
I´m having trouble with dynamic tabs, php code works fine. The problem is with bootstrap tabs.
Already tried updating bootstrap files and it did't work!
<ul class="nav nav-tabs nav-justified tabprofile" id="outerTab" role="tablist">
#foreach($parentCategories as $count => $category)
<li class="nav-item">
<a
#if($count == 0) class="nav-link fade show active " #else class="nav-link checklist" #endif
id="{{$category->id}}-tab" data-toggle="tab" href="#{{$category->id}}"
role="tab" aria-controls="{{$category->id}}" #if($count == 0) aria-selected="true" #else aria-selected="false" #endif>{{$category->name}}</a>
</li>
#endforeach
</ul>
<div class="tab-content">
#foreach($parentCategories as $count => $category)
<div #if($count == 0) class="tab-pane fade show active" #else class="tab-pane checklist" #endif id="{{$category->id}}" role="tabpanel" aria-labelledby="{{$category->id}}-tab" >
<ul class="nav nav-tabs nav-justified" id="innerTab" role="tablist">
#foreach($category->children as $count => $sub)
<li class="nav-item">
<a class="nav-link #if($count == 0) show active #endif" id="{{$sub->id}}-tab" data-toggle="tab" href="#{{$sub->id}}"
role="tab" aria-controls="{{$sub->id}}" #if($count == 0) aria-selected="true" #else aria-selected="false" #endif>{{$sub->slug}}</a>
</li>
#endforeach
</ul>
<div class="tab-content">
#foreach($category->children as $count => $sub)
<div #if($count == 0) class="tab-pane fade show active checklist" #else class="tab-pane checklist" #endif id="{{$sub->id}}" role="tabpanel" aria-labelledby="{{$sub->id}}-tab" >
<table class="table table-bordered">
<tbody>
#foreach($checklist->objectives->where('category_id', $sub->id) as $objective)
<tr>
<th>
{{$objective->competence}} - {{$objective->title}}
</th>
<td>
#switch($objective->pivot->status)
#case('Consistente')
<span class="badge badge-success">{{$objective->pivot->status}}</span>
#break
#case('Difícil de obter')
<span class="badge badge-danger">{{$objective->pivot->status}}</span>
#break
#case('Mais ou Menos')
<span class="badge badge-warning">{{$objective->pivot->status}}</span>
#break
#default
<span class="badge badge-secondary">{{$objective->pivot->status}}</span>
#break
#endswitch
</td>
</tr>
#endforeach
</tbody>
</table>
</div><!-- level content -->
#endforeach
</div><!-- tab-content -->
</div><!-- level content -->
#endforeach
I have tried mostly everything and it does not work.
Hope anyone can help me.. Thanks
I am using laravel 5.3
I have a responding navigation menu, when I click on domains, it shows all the domains I already have in DB, and then when I click on one of these domains I get the corresponding projects.
Now, I am want that when I click on project it displays all the corresponding data in a table for example. But, this is what I am getting :
this is ProjectController :
public function index(Request $request)
{
$projects1=DB::table('projects')->where('domain_id', '=', 1)->get();
$projects2=DB::table('projects')->where('domain_id', '=', 2)->get();
$projects3=DB::table('projects')->where('domain_id', '=', 3)->get();
return view('projects.index',compact('projects', 'projects1', 'projects2', 'projects3'));
}
and this is index.blade.php :
<div class="nav-side-menu">
<div class="brand">Menu</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li data-toggle="collapse" data-target="#products" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> Domains <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="products">
<li data-toggle="collapse" data-target="#domain1_projet" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> Domain 1 <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="domain1_projet">
#foreach ($projects1 as $key => $project)
<li>{{$project->title}}</li>
#endforeach
<table class="table table-bordered">
<tr>
<th>No</th>
<th>title</th>
<th>code</th>
<th>domain_id</th>
</tr>
#foreach ($projects1 as $key => $project1)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $project1->title }}</td>
<td>{{ $project1->code }}</td>
<td>{{ $project1->domain_id}}</td>
</tr>
#endforeach
</table>
</ul>
<li data-toggle="collapse" data-target="#domain2_projet" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> Domain 2 <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="domaine2_projet">
#foreach ($projects2 as $key => $project)
<li>{{$project->title}}</li>
#endforeach
</ul>
</ul>
</ul>
</div>
</div>
the #if clause I added before table was just to test, but I need to change that. I want to be able to display data of each project not in a manual way. I also want to know how to show and hide the information of each project when clicking on the links.
As you can see in index.blade.php, It's because I already know the names of project I did if (($project->intitule)=="Title") and elseif(($project->intitule)=="Project2") But, in fact I have many projects in database. How can I be able to display all the projects and then when I click on one of them, how can get a table containing information of that specific project
CONTROLLER
public function index(Request $request)
{
$projects=DB::table('projects')->get();
return view('projects.index',compact('projects'));
}
VIEW
<div class="nav-side-menu">
<div class="brand">Menu</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li data-toggle="collapse" data-target="#products" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> Domains <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="products">
#for ($i = 0; $i < count($projects); $i++)
<li data-toggle="collapse" data-target="#domain1_projet{{$i}}" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> Domain {{$projects[$i]->domain_id}} <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="domain1_projet{{$i}}">
<li>{{$projects[$i]->title}}</li>
<table class="table table-bordered">
<tr>
<th>No</th>
<th>title</th>
<th>code</th>
<th>domain_id</th>
</tr>
<tr>
<td>{{ $i }}</td>
<td>{{ $projects[$i]->title }}</td>
<td>{{ $projects[$i]->code }}</td>
<td>{{ $projects[$i]->domain_id}}</td>
</tr>
</table>
</ul>
#endfor
</ul>
</ul>
</div>
</div>
Try it! and let me know if return errors!