Skip to content

Commit

Permalink
try to return actual items
Browse files Browse the repository at this point in the history
  • Loading branch information
momijizukamori committed Aug 3, 2023
1 parent 1076707 commit 5abb9c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 23 additions & 1 deletion app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,35 @@ class SearchController extends Controller
{
public function index()
{
$query = Item::query();
$query->orderBy(...(sorted('added_new')));

$query->where('status', Item::PUBLISHED);

$paginator = $query->paginate(24);

$paginator->each(function (Item $item) {
$item->image = Storage::cloud()->url($item->image);
$item->makeVisible('image');

if ($item->brand !== null) {
$item->brand->image = Storage::cloud()->url($item->brand->image);
$item->brand->makeVisible('image');
}

if ($item->category !== null) {
$item->category->image = Storage::cloud()->url($item->category->image);
$item->category->makeVisible('image');
}
});

return view('search', ['sections' => [
'brands' => Brand::cached(),
'categories' => Category::cached(),
'features' => Feature::cached(),
'attributes' => Attribute::cached(),
'colors' => Color::cached(),
'tags' => Tag::cached(),],
'results' => []]);
'items' => $paginator]);
}
}
6 changes: 4 additions & 2 deletions resources/views/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="row">
<div class="col-xl-3 col-lg-4 col-md-6 col-sm-6 p-2" id="results">
@forelse ($results['items'] as $item)
@forelse ($items as $item)
@include('items.card', compact('item'))
@empty
<div style="height: 14rem">
Expand All @@ -28,11 +28,13 @@
</div>
</div>

@if ($items->count() > 0)
<div v-if="results && results.last_page > 1" class="row">
<div class="col mb-2 mt-4" id="pagination">
@include('components.pagination')
{{ $items->links() }}
</div>
</div>
@endif

</div>

Expand Down

0 comments on commit 5abb9c5

Please sign in to comment.