diff --git a/app/Http/Controllers/BlogController.php b/app/Http/Controllers/BlogController.php index 5402214..4985442 100644 --- a/app/Http/Controllers/BlogController.php +++ b/app/Http/Controllers/BlogController.php @@ -42,6 +42,16 @@ class BlogController extends Controller $query = $query->whereJsonContains('tags', $request->tag); } + // Search filtresi + if ($query && $request->has('search') && $request->search) { + $search = $request->search; + $query = $query->where(function($q) use ($search) { + $q->where('title', 'like', '%' . $search . '%') + ->orWhere('content', 'like', '%' . $search . '%') + ->orWhere('excerpt', 'like', '%' . $search . '%'); + }); + } + $posts = $query ? $query->latest('published_at')->paginate(12) : collect(); diff --git a/public/assets/js/theme.js b/public/assets/js/theme.js index 7422c5e..6ee5dfa 100644 --- a/public/assets/js/theme.js +++ b/public/assets/js/theme.js @@ -131,6 +131,7 @@ var theme = { if(grids != null) { grids.forEach(g => { var itemgrid = g.querySelector('.isotope'); + if (itemgrid == null) return; var filtersElem = g.querySelector('.isotope-filter'); var buttonGroups = g.querySelectorAll('.isotope-filter'); var iso = new Isotope(itemgrid, { @@ -216,9 +217,11 @@ var theme = { if (top >= offset && top < offset + height) { navLinks.forEach(links => { links.classList.remove('active'); - document.querySelector(`.nav-link.scroll[href*=${id}]`).classList.add('active'); - //[att*=val] Represents an element with the att attribute whose value contains at least one instance of the substring "val". If "val" is the empty string then the selector does not represent anything. }); + let activeLink = document.querySelector(`.nav-link.scroll[href*="${id}"]`); + if (activeLink) { + activeLink.classList.add('active'); + } } }); } @@ -237,11 +240,14 @@ var theme = { e.preventDefault(); this.blur(); const href = this.getAttribute("href"); - const offsetTop = document.querySelector(href).offsetTop; - scroll({ - top: offsetTop, - behavior: "smooth" - }); + const target = document.querySelector(href); + if (target) { + const offsetTop = target.offsetTop; + scroll({ + top: offsetTop, + behavior: "smooth" + }); + } } }, /** diff --git a/resources/views/blog/index.blade.php b/resources/views/blog/index.blade.php index d237594..aae99cf 100644 --- a/resources/views/blog/index.blade.php +++ b/resources/views/blog/index.blade.php @@ -7,7 +7,7 @@ @if(isset($carouselPosts) && $carouselPosts->count() > 0) -