ClearBowl/api/app/Http/Controllers/ProductsController.php
2019-12-05 15:19:09 +01:00

33 lines
892 B
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\AddProductRequest;
use App\Repositories\ProductsRepositoryInterface;
use Illuminate\Http\Request;
class ProductsController extends Controller
{
private $productsRepository;
private $paginationSize = 10;
public function __construct(ProductsRepositoryInterface $productsRepository)
{
$this->productsRepository = $productsRepository;
}
public function add(AddProductRequest $request)
{
$product = $this->productsRepository->create($request->all());
return response()->json(['success' => true, 'data' => ['product' => $product]], 200);
}
public function index(Request $request)
{
$products = $this->productsRepository->paginate($this->paginationSize);
return response()->json(['success' => true, 'data' => ['products' => $products]], 200);
}
}