summaryrefslogtreecommitdiff
path: root/src/products/app/Http/Controllers/ProductsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/products/app/Http/Controllers/ProductsController.php')
-rw-r--r--src/products/app/Http/Controllers/ProductsController.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/products/app/Http/Controllers/ProductsController.php b/src/products/app/Http/Controllers/ProductsController.php
new file mode 100644
index 0000000..7d55460
--- /dev/null
+++ b/src/products/app/Http/Controllers/ProductsController.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Product;
+use Illuminate\Http\Request;
+
+class ProductsController extends Controller
+{
+ public function get_all()
+ {
+ return response()->json(Product::all());
+ }
+
+ public function create(Request $request)
+ {
+ $this->validate($request, [
+ 'name' => 'required|unique:products'
+ ]);
+
+ $product = Product::create($request->all());
+
+ return response()->json($product, 201);
+ }
+
+ public function delete($id)
+ {
+ Product::FindOrFail($id)->delete();
+
+ return response('Deleted successfully', 200);
+ }
+}