ExtraFieldController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 28
c 1
b 0
f 1
dl 0
loc 65
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A store() 0 4 1
A index() 0 32 4
A update() 0 4 1
A destroy() 0 7 2
A edit() 0 3 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * ExtraFieldController
5
 *
6
 * This is the controller of the product weight types of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
13
use Hideyo\Ecommerce\Framework\Services\ExtraField\ExtraFieldFacade as ExtraFieldService;
14
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService;
15
16
use Illuminate\Http\Request;
17
use DataTables;
18
use Form;
19
20
class ExtraFieldController extends Controller
21
{
22
    public function index(Request $request)
23
    {
24
        if ($request->wantsJson()) {
25
26
            $query = ExtraFieldService::getModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id);
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
27
            
28
            $datatables = DataTables::of($query)
29
30
            ->addColumn('category', function ($query) {
31
                if ($query->categories) {
32
                    $output = array();
33
                    foreach ($query->categories as $categorie) {
34
                        $output[] = $categorie->title;
35
                    }
36
37
                    return implode(' | ', $output);
38
                }
39
            })
40
41
            ->addColumn('action', function ($query) {
42
                $deleteLink = Form::deleteajax(url()->route('extra-field.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
43
                $links = '<a href="'.url()->route('extra-field.values.index', $query->id).'" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>'.$query->values->count().' values</a>
44
                 <a href="'.url()->route('extra-field.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> 
45
                '.$deleteLink;
46
            
47
                return $links;
48
            });
49
50
            return $datatables->make(true);
51
        }
52
        
53
        return view('backend.extra-field.index')->with('extraField', ExtraFieldService::selectAll());
54
    }
55
56
    public function create()
57
    {
58
        return view('backend.extra-field.create')->with(array('productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id')));
59
    }
60
61
    public function store(Request $request)
62
    {
63
        $result  = ExtraFieldService::create($request->all());
64
        return ExtraFieldService::notificationRedirect('extra-field.index', $result, 'The extra field was inserted.');
65
    }
66
67
    public function edit($id)
68
    {
69
        return view('backend.extra-field.edit')->with(array('extraField' => ExtraFieldService::find($id), 'productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id')));
70
    }
71
72
    public function update(Request $request, $id)
73
    {
74
        $result  = ExtraFieldService::updateById($request->all(), $id);
75
        return ExtraFieldService::notificationRedirect('extra-field.index', $result, 'The extra field was updated.');
76
    }
77
78
    public function destroy($id)
79
    {
80
        $result  = ExtraFieldService::destroy($id);
81
82
        if ($result) {
83
            flash('Extra field was deleted.');
84
            return redirect()->route('extra-field.index');
85
        }
86
    }
87
}
88