sarga/packages/Webkul/API/Http/Controllers/Product/ProductController.php

76 lines
1.7 KiB
PHP
Raw Normal View History

2018-11-21 06:29:18 +00:00
<?php
namespace Webkul\API\Http\Controllers\Product;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
/**
2018-11-25 15:21:21 +00:00
* Product controller
2018-11-21 06:29:18 +00:00
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductController extends Controller
{
2018-11-25 15:21:21 +00:00
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* ProductRepository object
*
* @var array
*/
2018-11-21 06:29:18 +00:00
protected $product;
2018-11-25 15:21:21 +00:00
/**
* Create a new controller instance.
*
* @param Webkul\Product\Repositories\ProductRepository $product
* @return void
*/
public function __construct( Product $product)
2018-11-21 06:29:18 +00:00
{
$this->product = $product;
2018-11-25 15:21:21 +00:00
$this->_config = request('_config');
2018-11-21 06:29:18 +00:00
}
2018-11-25 15:21:21 +00:00
/**
* Display a listing of the resource.
*
* @param string $slug
* @return \Illuminate\Http\Response
*/
public function getBySlug($slug)
{
$product = $this->product->findBySlugOrFail($slug);
return response()->json(['message' => 'success', 'product' => $product]);
}
public function getAll() {
2018-11-21 06:29:18 +00:00
$products = $this->product->all();
return response()->json($products, 200);
}
2018-11-25 15:21:21 +00:00
public function getNew() {
$newProducts = $this->product->getNewProducts();
2018-11-21 06:29:18 +00:00
return response()->json($newProducts, 200);
}
2018-11-25 15:21:21 +00:00
public function getFeatured() {
$featuredProducts = $this->product->getFeaturedProducts();
return response()->json($featuredProducts, 200);
}
}