Last active
June 13, 2020 16:05
-
-
Save victorhugorch/bea7fc1708384b911aa1b4c99496d14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Models\Product; | |
use Illuminate\Http\JsonResponse; | |
use App\Http\Requests\ProductRequest; | |
use Symfony\Component\HttpFoundation\Response; | |
class ProductsController extends Controller | |
{ | |
/** | |
* @var ProductsService | |
*/ | |
private $productsService; | |
/** | |
* ProductsController constructor. | |
* @param ProductsService $productsService | |
*/ | |
public function __construct( | |
ProductsService $productsService | |
) | |
{ | |
$this->productsService = $productsService; | |
} | |
public function store(ProductRequest $productRequest) : JsonResponse | |
{ | |
$product = $this->productService->create( | |
$productRequest->name, | |
$productRequest->description, | |
$productRequest->quantity, | |
$productRequest->price | |
); | |
return response()->json([ | |
'message' => 'Product created successfully!, | |
'data' => $product | |
], Response::HTTP_CREATED); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment