AttributeGroupController::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 2
c 2
b 1
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * AttributeGroupController
5
 *
6
 * This is the controller of the attributes groups used by products of the shop
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 AttributeGroupController 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)
28
    {
29
        if ($request->wantsJson()) {
30
            $query = AttributeService::getGroupModel()->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...
31
            
32
            $datatables = DataTables::of($query)->addColumn('action', function ($query) {
33
                $deleteLink = Form::deleteajax(url()->route('attribute-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
34
                $links = '
35
                    <a href="'.url()->route('attribute.index', $query->id).'" class="btn btn-sm btn-info"><i class="entypo-pencil"></i>'.$query->attributes->count().' Attributes</a>
36
                    <a href="'.url()->route('attribute-group.edit', $query->id).'" class="btn btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> 
37
                '.$deleteLink;
38
                return $links;
39
            });
40
41
            return $datatables->make(true);
42
        }
43
            
44
        return view('backend.attribute-group.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('backend.attribute-group.index') returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Backend\View.
Loading history...
45
    }
46
47
    public function create()
48
    {
49
        return view('backend.attribute-group.create');
50
    }
51
52
    public function store(Request $request)
53
    {
54
        $result  = AttributeService::createGroup($request->all());
55
        return AttributeService::notificationRedirect('attribute-group.index', $result, 'The attribute group was inserted.');
56
    }
57
58
    public function edit($attributeGroupId)
59
    {
60
        return view('backend.attribute-group.edit')->with(array('attributeGroup' => AttributeService::findGroup($attributeGroupId)));
61
    }
62
63
    public function update(Request $request, $attributeGroupId)
64
    {
65
        $result  = AttributeService::updateGroupById($request->all(), $attributeGroupId);
66
        return AttributeService::notificationRedirect('attribute-group.index', $result, 'The attribute group was updated.');
67
    }
68
69
    public function destroy($attributeGroupId)
70
    {
71
        $result  = AttributeService::destroyGroup($attributeGroupId);
72
73
        if ($result) {
74
            flash('Attribute group was deleted.');
75
            return redirect()->route('attribute-group.index');
76
        }
77
    }
78
}
79