I have an array of items that I'm using in Laravel (in the array, half are "parent items" and half are "child Items")
Say the array is 30 items, 15 of each type, I'm trying to get a result where I would have a single accordian header that says "Parent items" with the 15 parent items under the single header, then a single accordian header for the "Child items" with those 15 under it.
However, with my current code I'm getting the header over each individual item.
I understand this is because of the foreach, but I'm stumped on how exactly to achieve what I'm looking for and I just can't seem to get around the issue of the header over each item
What am I doing wrong here?
#foreach($items as $item)
#if($item['type'] == "Parent Item")
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Main/Parent Items
</button>
</h2>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
{{$item['Description']}}
</div>
</div>
</div>
</div>
#elseif($item['type'] == "Child Item")
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Sub/Child Items
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
{{$item['Description']}}
</div>
</div>
</div>
</div>
#endif
#endforeach
You'll just need to do 2 loops, ie:
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Main/Parent Items
</button>
</h2>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
#foreach($items as $item)
#if($item['type'] == "Parent Item")
<div class="card-body">
{{$item['Description']}}
</div>
#endif
#endforeach
</div>
</div>
</div>
<div class="accordion" id="accordionExample2">
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Sub/Child Items
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordionExample2">
#foreach($items as $item)
#if($item['type'] == "Child Item")
<div class="card-body">
{{$item['Description']}}
</div>
#endif
#endforeach
</div>
</div>
</div>
As a side note that id="accordionExample" on both elements is invalid, those should have unique ids.
Related
I have a huge list of clients in a table, I have changed the design to boostrabs grids, but now I have a problem and it is that all the contacts are shown in an endless page, it is very long
enter image description here
Php code
<?php if(count($customers)): foreach($customers as $ct): ?>
<div class="row">
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-body">
<div class="dropdown float-end">
<a class="text-muted dropdown-toggle font-size-16" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true"><i class="bx bx-dots-horizontal-rounded"></i></a>
<div class="dropdown-menu dropdown-menu-end"><a class="dropdown-item" href="#">Edit</a><a class="dropdown-item" href="#">Action</a><a class="dropdown-item" href="#">Remove</a></div>
</div>
<div class="d-flex align-items-center">
<div><img src="https://bootdey.com/img/Content/avatar/avatar1.png" alt="" class="avatar-md rounded-circle img-thumbnail" /></div>
<div class="flex-1 ms-3">
<h5 class="font-size-16 mb-1"><?php echo $ct->first_name ?></h5>
<span class="badge badge-soft-success mb-0"><?php echo $ct->dni ?></span>
</div>
</div>
<div class="mt-3 pt-1">
<p class="text-muted mb-0"><i class="mdi mdi-phone font-size-15 align-middle pe-2 text-primary"></i><?php echo $ct->mobile ?></p>
<p class="text-muted mb-0 mt-2"><i class="mdi mdi-email font-size-15 align-middle pe-2 text-primary"></i> <?php echo $ct->gender ?></p>
<p class="text-muted mb-0 mt-2"><i class="mdi mdi-google-maps font-size-15 align-middle pe-2 text-primary"></i><?php echo $ct->company ?>/p>
</div>
<div class="d-flex gap-2 pt-4">
<button type="button" class="btn btn-soft-primary btn-sm w-50"><i class="bx bx-user me-1"></i> Profile</button>
<button type="button" class="btn btn-primary btn-sm w-50"><i class="bx bx-message-square-dots me-1"></i> Contact</button>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="7" class="text-center">No existen Clientes, agregar un nuevo cliente.</td>
</tr>
<?php endif; ?>
</div>
</div>
</div>
</div>
I need 10 contacts to appear per page
I am having trouble restricting menu options for user roles in Laravel 7. The menu for 'admin' and 'profesor' are similar but I decided to make two different views for each one and make an #include in the main view.
User model
public function roles()
{
return $this->belongsToMany(Role::class,'assigned_roles');
}
public function isAdmin()
{
return $this->hasRoles(['admin']);
}
public function hasRoles(array $roles)
{
foreach ($roles as $role) {
foreach ($this->roles as $userRole) {
if ($userRole->name === $role) {
return true;
}
}
}
return false;
}
public function userRole()
{
return $this->role->nombre_rol;
}
My view
<hr class="hr-unam">
#if (auth()->user()->hasRoles(['admin']))
<div class="sideover">
<!-- *********************** SERVESCOL *********************** -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h5 class=" text-center panel-title">
<a class="txt-unam txt-side font-weight-bold text-uppercase" style="text-decoration:none" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
SERVESCOL
</a>
</h5>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class="panel-group" id="sub-accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="subHeadingOne">
<a role="button" data-toggle="collapse" data-parent="#sub-accordion" href="#collapseSubOne" aria-expanded="true" aria-controls="collapseSubOne">
#include('main.sidebarServescol')
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr class="hr-unam">
#else
#if(auth()->user()->hasRoles(['profesor']))
<!-- *********************** SERVESCOL *********************** -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h5 class=" text-center panel-title">
<a class="txt-unam txt-side font-weight-bold text-uppercase" style="text-decoration:none" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
SERVESCOL
</a>
</h5>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class="panel-group" id="sub-accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="subHeadingOne">
<a role="button" data-toggle="collapse" data-parent="#sub-accordion" href="#collapseSubOne" aria-expanded="true" aria-controls="collapseSubOne">
#include('main.sidebarProfesor')
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr class="hr-unam">
#endif
#endif
But both options disappear and the view breaks down. I have also tried it within the views of each menu directly, but in both, the role of 'admin' as in the role of 'profesor', remove the option that covers the #if.
Your hasRoles function could be a bit simpler
public function hasRoles(array $roles)
{
return $this->roles->contains(function ($role, $key) use ($roles) {
return in_array($role->name, $roles);
});
}
// PHP 7.4 and above
public function hasRoles(array $roles)
{
return $this->roles->contains(fn($role, $key) => in_array($role->name, $roles));
}
You could use the #includeWhen directive.
<hr class="hr-unam">
<div class="sideover">
<!-- *********************** SERVESCOL *********************** -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h5 class=" text-center panel-title">
<a class="txt-unam txt-side font-weight-bold text-uppercase" style="text-decoration:none" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
SERVESCOL
</a>
</h5>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class="panel-group" id="sub-accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="subHeadingOne">
<a role="button" data-toggle="collapse" data-parent="#sub-accordion" href="#collapseSubOne" aria-expanded="true" aria-controls="collapseSubOne">
#includeWhen(auth()->user()->hasRoles(['admin']), 'main.sidebarServescol')
#includeWhen(auth()->user()->hasRoles(['profesor']), 'main.sidebarProfesor')
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I have all my products in view:welcome.blade.php and The problem is how can I show modal with the details of a specific id?
<!-- End Product MEnu -->
<div class="row product__list">
#foreach($products as $product)
<!-- Start Single Product -->
<div class="col-md-3 single__pro col-lg-3 col-md-4 cat--1 col-sm-12">
<div class="product foo">
<div class="product__inner">
<div class="pro__thumb">
<a href="#">
<img src="{{ asset('storage/products/' . $product->image ) }}" width="270px" height="270px" alt="product images">
</a>
</div>
<div class="product__hover__info">
<ul class="product__action">
<li><a id="{{ $product->id }}" data-toggle="modal" data-target="#productModal" title="Quick View" class="quick-view modal-view detail-link viewDetails" href="#"><span class="ti-plus"></span></a></li>
<li><a title="Add TO Cart" href="cart.html"><span class="ti-shopping-cart"></span></a></li>
</ul>
</div>
<div class="add__to__wishlist">
<a data-toggle="tooltip" title="Add To Wishlist" class="add-to-cart" href="wishlist.html"><span class="ti-heart"></span></a>
</div>
</div>
<div class="product__details">
<h2>{{ $product->name }}</h2>
<ul class="product__price">
{{-- <li class="old__price">$16.00</li> --}}
<li class="new__price">₹ {{ $product->price }}</li>
</ul>
</div>
</div>
</div>
<!-- End Single Product -->
#endforeach
How can i show the details of a product in a modal?
Please Change Your data-target="#productModal{{ $product->id }}"
<div class="product__hover__info">
<ul class="product__action">
<li><span class="ti-plus"></span></li>
<li><a title="Add TO Cart" href="cart.html"><span class="ti-shopping-cart"></span></a></li>
</ul>
</div>
<div class="modal fade" id="productModal{{ $product->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
{{$product->id}}
</div>
</div>
</div>
</div>
I created an accordion and div. The accordion is working. I want to put php files in div. When I clicked a list link I want to bring page content on the div. How should I track a way? İs there another way?. You can see https://jsfiddle.net/y8fuwtg6/1/
<div style="width:200px; float:left; margin:20px 20px;">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
List1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<a href="index1.php">
List1
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
List2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<a href="index2.php">
List2
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
List3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
<a href="index3.php">
List3
</a>
</div>
</div>
</div>
</div>
<div id="test" style="width: 150px; min-height:200px; background-color: #cdcdcd; margin:20px 20px; height: auto; display:inline-block;">
</div>
I solved my problem. I just used a script. İt can solve with ajax. Maybe this document may help someone.
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/bootstrap.min.css" >
<link rel="stylesheet" href="css/bootstrap-theme.min.css" >
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div style="width:400px; float:left;">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
List1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<a href="homepage.php">
List1
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
List2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<a href="computer.php">
List2
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
List3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
<a href="electronic.php">
List3
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingFour">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
List4
</a>
</h4>
</div>
<div id="collapseFour" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFour">
<div class="panel-body">
<a href="phone.php">
List4
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingFive">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseFive" aria-expanded="false" aria-controls="collapseFive">
List5
</a>
</h4>
</div>
<div id="collapseFive" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingFive">
<div class="panel-body">
<a href="books.php">
List5
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingSix">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseSix" aria-expanded="false" aria-controls="collapseSix">
List6
</a>
</h4>
</div>
<div id="collapseSix" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingSix">
<div class="panel-body">
<a href="services.php">
List6
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingSeven">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseSeven" aria-expanded="false" aria-controls="collapseSeven">
List7
</a>
</h4>
</div>
<div id="collapseSeven" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingSeven">
<div class="panel-body">
<a href="contact.php">
List7
</a>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingEight">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseEight" aria-expanded="false" aria-controls="collapseEight">
List8
</a>
</h4>
</div>
<div id="collapseEight" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingEight">
<div class="panel-body">
<a href="about.php">
List8
</a>
</div>
</div>
</div>
</div>
</div>
<div id="test" style="width: 600px; background-color: #cdcdcd; margin-left: 20px; height: auto; display:inline-block;">
</div>
<script>
$(".panel-body a").click(function(){
var x=$(this).attr("href");
$("#test").load(x);
return false;
});
</script>
</body>
</html>
I am trying to do an accordion collapse/fold however i am not set on it being an according, standard collapse/fold is fine if the accordion effect is troublesome however i want it to show initially with all fields collapsed.
Bear in mind i am doing a loop to create each one, that might be irrelevant as i can add in a different id,class on the first loop no problem but just worth mentioning it.
So i have this:
<div class="row">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
Title1
</a>
</h5>
</div>
<div id="collapse1" class="panel-collapse collapse in">
<div class="panel-body">
Content1
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
Title2
</a>
</h5>
</div>
<div id="collapse2" class="panel-collapse collapse in">
<div class="panel-body">
Content2
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse3">
Title3
</a>
</h5>
</div>
<div id="collapse3" class="panel-collapse collapse in">
<div class="panel-body">
Content3
</div>
</div>
</div>
</div>
</div>
Then i have the following script
<script>
$(function() {
var $active = true;
$('.panel-title > a').click(function(e) {
e.preventDefault();
});
$('.collapse-init').on('click', function() {
if(!$active) {
$active = true;
$('.panel-title > a').attr('data-toggle', 'collapse');
$('.panel-collapse').collapse({'toggle': true, 'parent': '#accordion'});
$(this).html('Click to disable accordion behavior');
} else {
$active = false;
$('.panel-collapse.in').removeClass('in');
$('.panel-collapse').collapse({'toggle': true, 'parent': '#accordion'});
$('.panel-title > a').removeAttr('data-toggle');
$(this).html('Click to enable accordion behavior');
}
});
});
</script>
I have messed around with it in the chrome editor to try and edit the class from collapse to collapse in and vice versa on them all but nothing seems to force it to collapse them all. One always remains open.
Just remove the in class from your <div id="collapse1" class="panel-collapse collapse in">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
Title1
</a>
</h5>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
Content1
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
Title2
</a>
</h5>
</div>
<div id="collapse2" class="panel-collapse collapse">
<div class="panel-body">
Content2
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse3">
Title3
</a>
</h5>
</div>
<div id="collapse3" class="panel-collapse collapse">
<div class="panel-body">
Content3
</div>
</div>
</div>
</div>
</div>