summaryrefslogtreecommitdiff
path: root/src/products/app/Http/Controllers/ProductsController.php
blob: 7d554605e7fdebf476b0c4d192c3afa6f44aa023 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
	}
}