summaryrefslogtreecommitdiff
path: root/src/products/app/Http/Controllers/ProductsController.php
diff options
context:
space:
mode:
authorMichiel Schuurmans <michielschuurmans@gmail.com>2020-10-01 21:17:03 +0200
committerMichiel Schuurmans <michielschuurmans@gmail.com>2020-10-01 21:17:03 +0200
commit20600ae10edbfde6a0613c67d5e40438b029578b (patch)
tree1091fec4a4a599ca2f3ffc0df90f802d49e4355f /src/products/app/Http/Controllers/ProductsController.php
parent70374ba862eb87c66f1e0d3afd4aedb416b33e9d (diff)
Products: Basic get/post/delete
Signed-off-by: Michiel Schuurmans <michielschuurmans@gmail.com>
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);
+ }
+}