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