ProductRelatedProductController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 23
c 2
b 0
f 1
dl 0
loc 48
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 7 2
A store() 0 4 1
A index() 0 24 2
A create() 0 5 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
4
/**
5
 * ProductRelatedProductController
6
 *
7
 * This is the controller of the product related products of the shop
8
 * @author Matthijs Neijenhuijs <[email protected]>
9
 * @version 0.1
10
 */
11
12
use App\Http\Controllers\Controller;
13
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
14
use Hideyo\Ecommerce\Framework\Services\Product\ProductRelatedProductFacade as ProductRelatedProductService;
15
use Illuminate\Http\Request;
16
17
class ProductRelatedProductController extends Controller
18
{
19
    public function index(Request $request, $productId)
20
    {
21
        $product = ProductService::find($productId);
22
        if ($request->wantsJson()) {
23
24
            $query = ProductRelatedProductService::getModel()->where('product_id', '=', $productId);
25
            
26
            $datatables = \DataTables::of($query)
27
                ->addColumn('related', function ($query) use ($productId) {
0 ignored issues
show
Unused Code introduced by
The import $productId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
28
                    return $query->RelatedProduct->title;
29
                })
30
                ->addColumn('product', function ($query) use ($productId) {
0 ignored issues
show
Unused Code introduced by
The import $productId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
31
                    return $query->Product->title;
32
                })
33
                ->addColumn('action', function ($query) use ($productId) {
34
                    $deleteLink = \Form::deleteajax(url()->route('product.related-product.destroy', array('productId' => $productId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
35
                    
36
                    return $deleteLink;
37
                });
38
39
                return $datatables->make(true);
40
        }
41
        
42
        return view('backend.product_related_product.index')->with(array('product' => $product));
43
    }
44
45
    public function create($productId)
46
    {
47
        $product = ProductService::find($productId);
48
        $products = ProductService::selectAll()->pluck('title', 'id');
49
        return view('backend.product_related_product.create')->with(array('products' => $products, 'product' => $product));
50
    }
51
    
52
    public function store(Request $request, $productId)
53
    {
54
        $result  = ProductRelatedProductService::create($request->all(), $productId);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
55
        return redirect()->route('product.related-product.index', $productId);
56
    }
57
58
    public function destroy($productId, $productRelatedProductId)
59
    {
60
        $result  = ProductRelatedProductService::destroy($productRelatedProductId);
61
62
        if ($result) {
63
            flash('The related product is deleted.');
64
            return redirect()->route('product.related-product.index', $productId);
65
        }
66
    }
67
}
68