2016-01-30 10:56:27 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Product;
|
2016-05-02 15:12:37 +02:00
|
|
|
use App\Ninja\Repositories\ProductRepository;
|
|
|
|
use App\Http\Requests\CreateProductRequest;
|
|
|
|
use App\Http\Requests\UpdateProductRequest;
|
2016-01-30 10:56:27 +01:00
|
|
|
|
|
|
|
class ProductApiController extends BaseAPIController
|
|
|
|
{
|
2016-05-01 22:55:13 +02:00
|
|
|
protected $productRepo;
|
|
|
|
|
|
|
|
protected $entityType = ENTITY_PRODUCT;
|
2016-02-01 03:32:12 +01:00
|
|
|
|
2016-05-02 15:12:37 +02:00
|
|
|
public function __construct(ProductRepository $productRepo)
|
2016-01-30 10:56:27 +01:00
|
|
|
{
|
2016-03-02 15:36:46 +01:00
|
|
|
parent::__construct();
|
2016-01-30 10:56:27 +01:00
|
|
|
|
2016-02-01 03:32:12 +01:00
|
|
|
$this->productRepo = $productRepo;
|
2016-01-30 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2016-05-01 22:55:13 +02:00
|
|
|
$products = Product::scope()
|
|
|
|
->withTrashed()
|
|
|
|
->orderBy('created_at', 'desc');
|
2016-01-30 11:51:52 +01:00
|
|
|
|
2016-05-02 10:38:01 +02:00
|
|
|
return $this->listResponse($products);
|
2016-01-30 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
2016-05-02 15:12:37 +02:00
|
|
|
public function store(CreateProductRequest $request)
|
2016-01-30 10:56:27 +01:00
|
|
|
{
|
2016-05-02 15:12:37 +02:00
|
|
|
$product = $this->productRepo->save($request->input());
|
2016-01-30 10:56:27 +01:00
|
|
|
|
2016-05-02 15:12:37 +02:00
|
|
|
return $this->itemResponse($product);
|
2016-01-30 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
2016-05-02 15:12:37 +02:00
|
|
|
public function update(UpdateProductRequest $request, $publicId)
|
2016-01-30 10:56:27 +01:00
|
|
|
{
|
2016-05-02 15:12:37 +02:00
|
|
|
if ($request->action) {
|
|
|
|
return $this->handleAction($request);
|
2016-02-01 03:32:12 +01:00
|
|
|
}
|
2016-05-02 15:12:37 +02:00
|
|
|
|
|
|
|
$data = $request->input();
|
|
|
|
$data['public_id'] = $publicId;
|
2016-05-02 19:42:13 +02:00
|
|
|
$product = $this->productRepo->save($data, $request->entity());
|
2016-05-02 15:12:37 +02:00
|
|
|
|
|
|
|
return $this->itemResponse($product);
|
2016-01-30 10:56:27 +01:00
|
|
|
}
|
|
|
|
|
2016-01-30 12:29:22 +01:00
|
|
|
public function destroy($publicId)
|
2016-01-30 10:56:27 +01:00
|
|
|
{
|
2016-02-01 03:32:12 +01:00
|
|
|
//stub
|
2016-01-30 10:56:27 +01:00
|
|
|
}
|
|
|
|
}
|