$("body").on("click","#delete",function(e){
var id = $(this).attr('data-id');
$post->id
url: "{{route('deletePost',['id' => $post->id])}}",
success: function (response){
$("#deletePost").html(response.message);
}
$parts = Part::with('categories')->where('parts.brand_id','=', $brand->id)->get(); // Получил запчасти привязанные к бренду
foreach($parts as $part)
{
foreach($part->categories as $category)
{
// Привязываем категорию к бренду через pivot;
}
}
public function partsByBrand($brand, $category)
{
if(isset($category) && !empty($category))
{
$parts = Part::where('brand_id', '=', $brand->id)->whereHas('categories', function ($query) use ($category)
{
return $query->where('category_id', $category->id);
})->get();
return $parts;
}
$brand_categories = PartCategory::whereHas('parts', function($query) use ($brand)
{
return $query->whereHas('brand', function($query) use ($brand) {
return $query->where('brand_id', $brand->id);
});
})->orderBy('created_at', 'desc')->get();
return $brand_categories;
}
По идее сделать так:
<div id="content" >
<h1><?php echo $heading_title; ?></h1>
<?php if ($categories) { ?>
<div class="manufaklist">
<?php foreach ($categories as $category) { ?>
<?php foreach (array_chunk($category['manufacturer'], 4) as $manufacturers) { ?>
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="item">
<a href="<?php echo $manufacturer['href']; ?>"><?php echo $manufacturer['name']; ?></a>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<?php } else { ?>
</div>
(() => {
var foo = function() {
var targetblock = document.getElementById('targetblock');
targetblock.insertAdjacentHTML("beforeend", "<div id='lumos-container'><span id='lumos-close' style='position: absolute; right: 15px; top: 15px; padding: 10px 15px; background: #ededed; border-radius: 5px; color: #666;'>Закрыть</span><img src='' id='lumos-image'></div>");
const lummContainer = document.getElementById('content'); // добавил контейнер
const lumosContainer = document.getElementById('lumos-container');
const lumosImage = document.getElementById('lumos-image');
const elements = document.querySelectorAll('[data-action="lumos"]');
const transitionSpeedInMilliseconds = 250;
window.addEventListener('keyup', (event) => {
if (event.key === 'Escape') {
hideLumos();
}
});
// elements.forEach((element) => {
// element.addEventListener('click', () => {
// handleElementClick(element);
// });
// });
lummContainer.onclick = (e) => {
var target = e.target; // элемент который вызвал событие
var action = target.dataset.action;
if (action == 'lumos') {
handleElementClick(target);
}
}
lumosContainer.addEventListener('click', hideLumos);
function handleElementClick(htmlElement) {
updateLumosImage(getImageUrl(htmlElement));
showLumos();
}
function getImageUrl(htmlElement) {
return htmlElement.attributes['data-lumos-src'] === undefined
? htmlElement.attributes['src'].value
: htmlElement.attributes['data-lumos-src'].value;
}
function updateLumosImage(imageUrl) {
lumosImage.attributes['src'].value = imageUrl;
}
function showLumos() {
if (!lumosContainerIsVisible()) {
lumosContainer.classList.remove('hidden');
lumosContainer.classList.add('visible');
}
}
function hideLumos() {
if (lumosContainerIsVisible()) {
lumosContainer.classList.add('hidden');
setTimeout(() => {
lumosContainer.classList.remove('visible');
lumosContainer.classList.remove('hidden');
lumosImage.attributes['src'].value = '';
}, transitionSpeedInMilliseconds);
}
}
function lumosContainerIsVisible() {
return lumosContainer.classList.contains('visible');
}
};
document.addEventListener("DOMContentLoaded", function(event) {
foo();
console.log("Загрузка DOMContentLoaded произошла!");
});
})();