21 lines
686 B
PHP
21 lines
686 B
PHP
<?php
|
|
|
|
namespace Modules\Commerce\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Modules\Commerce\Models\Product;
|
|
|
|
final class ProductApiController extends Controller
|
|
{
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json(Product::query()->where('status', 'active')->where(fn ($q) => $q->whereNull('published_at')->orWhere('published_at', '<=', now()))->latest()->paginate(24));
|
|
}
|
|
|
|
public function show(string $product): JsonResponse
|
|
{
|
|
return response()->json(Product::where('status', 'active')->where(fn ($q) => $q->where('slug', $product)->orWhere('id', $product))->firstOrFail());
|
|
}
|
|
}
|