AttributeController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 87
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 7 2
A index() 0 17 2
A create() 0 3 1
A update() 0 4 1
A edit() 0 3 1
A store() 0 4 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * AttributeController
5
 *
6
 * This is the controller of the attributes of a attribute group
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Illuminate\Http\Request;
13
use DataTables;
14
use Form;
15
16
use Hideyo\Ecommerce\Framework\Services\Attribute\AttributeFacade as AttributeService;
17
18
class AttributeController extends Controller
19
{
20
    /**
21
     * Display a listing of the resource.
22
     * @param  \Illuminate\Http\Request  $request
23
     * @param  integer $attributeGroupId for relation with attributeGroup
24
     * @return View
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Backend\View was not found. Did you mean View? If so, make sure to prefix the type with \.
Loading history...
25
     * @return datatables
26
     */
27
    public function index(Request $request, $attributeGroupId)
28
    {
29
        if ($request->wantsJson()) {
30
            $query = AttributeService::getModel()->where('attribute_group_id', '=', $attributeGroupId);
31
            
32
            $datatables = DataTables::of($query)
33
            ->addColumn('action', function ($query) use ($attributeGroupId) {
34
                $deleteLink = Form::deleteajax(url()->route('attribute.destroy', array('attributeGroupId' => $attributeGroupId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
35
                $links = ' <a href="'.url()->route('attribute.edit', array('attributeGroupId' => $attributeGroupId, 'id' => $query->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>'.$deleteLink;
36
                return $links;
37
            });
38
39
            return $datatables->make(true);
40
        }
41
        
42
        return view('backend.attribute.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('backend.att...oup($attributeGroupId)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Backend\View.
Loading history...
43
            ->with('attributeGroup', AttributeService::findGroup($attributeGroupId));
44
    }
45
46
    /**
47
     * Show the form for creating a new resource.
48
     * @param  integer $attributeGroupId for relation with attributeGroup
49
     * @return view
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Backend\view was not found. Did you mean view? If so, make sure to prefix the type with \.
Loading history...
50
     */
51
    public function create($attributeGroupId)
52
    {
53
        return view('backend.attribute.create')->with(array('attributeGroup' =>  AttributeService::findGroup($attributeGroupId)));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('backend.att...up($attributeGroupId))) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Backend\view.
Loading history...
54
    }
55
56
    /**
57
     * Store a newly created resource in storage.
58
     * @param  \Illuminate\Http\Request  $request
59
     * @param  integer $attributeGroupId for relation with attributeGroup
60
     * @return Redirect
61
     */
62
    public function store(Request $request, $attributeGroupId)
63
    {
64
        $result  = AttributeService::create($request->all(), $attributeGroupId);
65
        return AttributeService::notificationRedirect(array('attribute.index', $attributeGroupId), $result, 'The attribute was inserted.');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Hideyo\Ecommerce\...tribute was inserted.') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Backend\Redirect.
Loading history...
66
    }
67
68
    /**
69
     * Show the form for editing the specified resource.
70
     * @param  integer $attributeGroupId for relation with attributeGroup
71
     * @param  int  $attributeId
72
     * @return Redirect
73
     */
74
    public function edit($attributeGroupId, $attributeId)
75
    {
76
        return view('backend.attribute.edit')->with(array('attributeGroupId' => $attributeGroupId, 'attribute' => AttributeService::find($attributeId)));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('backend.att...e::find($attributeId))) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Backend\Redirect.
Loading history...
77
    }
78
79
    /**
80
     * Update the specified resource in storage.
81
     * @param  \Illuminate\Http\Request  $request
82
     * @param  integer $attributeGroupId for relation with attributeGroup
83
     * @param  int  $attributeId
84
     * @return Redirect
85
     */
86
    public function update(Request $request, $attributeGroupId, $attributeId)
87
    {
88
        $result  = AttributeService::updateById($request->all(), $attributeGroupId, $attributeId);
89
        return AttributeService::notificationRedirect(array('attribute.index', $attributeGroupId), $result, 'The attribute was updated.');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Hideyo\Ecommerce\...ttribute was updated.') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Backend\Redirect.
Loading history...
90
    }
91
92
    /**
93
     * Remove the specified resource from storage
94
     * @param  integer $attributeGroupId for relation with attributeGroup
95
     * @param  int  $attributeId
96
     * @return Redirect
97
     */
98
    public function destroy($attributeGroupId, $attributeId)
99
    {
100
        $result  = AttributeService::destroy($attributeId);
101
102
        if ($result) {
103
            flash('Atrribute was deleted.');
104
            return redirect()->route('attribute.index', $attributeGroupId);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ex', $attributeGroupId) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Backend\Redirect.
Loading history...
105
        }
106
    }
107
}