Passed
Push — master ( 3ed185...d0305f )
by Gianluca
04:49
created

AdminNewProductController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
c 1
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A page() 0 2 1
A createNewProduct() 0 19 1
1
<?php
2
3
4
namespace Mongi\Mongicommerce\Http\Controllers\admin;
5
6
7
use Illuminate\Http\Request;
8
use Mongi\Mongicommerce\Http\Controllers\Controller;
9
use Mongi\Mongicommerce\Models\Product;
10
use Mongi\Mongicommerce\Models\ProductItem;
11
use Mongi\Mongicommerce\Models\ProductItemDetail;
12
13
class AdminNewProductController extends Controller
14
{
15
    public function page(){
16
        return view('mongicommerce::admin.pages.products.new_product');
17
    }
18
19
    public function createNewProduct(Request $r){
20
21
        $r->validate([
22
            'product_name' => 'required',
23
            'product_description' => 'required',
24
            'category_id' => 'required',
25
        ]);
26
27
        $product_name = $r->get('product_name');
28
        $product_description = $r->get('product_description');
29
        $category_id = $r->get('category_id');
30
31
        $product = new Product();
32
        $product->name = $product_name;
33
        $product->description = $product_description;
34
        $product->category_id = $category_id;
35
        $product->save();
36
37
        return response()->json(['product_id' => $product->id]);
38
    }
39
}
40