generated from boboko/starter
30 lines
883 B
PHP
30 lines
883 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use Lunar\Models\Collection;
|
||
|
|
use Lunar\Models\Product;
|
||
|
|
|
||
|
|
class CategoryController extends Controller
|
||
|
|
{
|
||
|
|
public function show(string $locale, Collection $collection)
|
||
|
|
{
|
||
|
|
$products = $collection
|
||
|
|
->products()
|
||
|
|
->with(['variants.prices.currency', 'media'])
|
||
|
|
->paginate(12)
|
||
|
|
->withQueryString()
|
||
|
|
->through(fn (Product $product) => [
|
||
|
|
'name' => $product->translateAttribute('name'),
|
||
|
|
'price' => $product->variants->first()?->prices->first()?->price->decimal,
|
||
|
|
'image' => $product->media->first()?->getUrl(),
|
||
|
|
'href' => route('product.show', ['product' => $product]),
|
||
|
|
]);
|
||
|
|
|
||
|
|
return view('category.show', [
|
||
|
|
'collection' => $collection,
|
||
|
|
'products' => $products,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|