Passed
Push — master ( 65a680...2232db )
by Matthijs
17:59 queued 12:07
created

ExtraFieldDefaultValueController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
/**
3
 * ExtraFieldDefaultValueController
4
 *
5
 * This is the controller of the product weight types of the shop
6
 * @author Matthijs Neijenhuijs <[email protected]>
7
 * @version 0.1
8
 */
9
10
use App\Http\Controllers\Controller;
11
use Hideyo\Ecommerce\Framework\Services\ExtraField\ExtraFieldFacade as ExtraFieldService;
12
13
use Illuminate\Http\Request;
14
use Notification;
15
use Datatables;
0 ignored issues
show
Bug introduced by
The type Datatables was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Form;
17
18
class ExtraFieldDefaultValueController extends Controller
19
{
20
    public function index(Request $request, $extraFieldId)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = ExtraFieldService::getValueModel()->select(
25
                [
26
                
27
                'id',
28
                'value']
29
            )->where('extra_field_id', '=', $extraFieldId);
30
            
31
            $datatables = Datatables::of($query)->addColumn('action', function ($query) use ($extraFieldId) {
32
                $deleteLink = Form::deleteajax(url()->route('extra-field.values.destroy', array('ExtraFieldId' => $extraFieldId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
33
                $links = ' <a href="'.url()->route('extra-field.values.edit', array('ExtraFieldId' => $extraFieldId, 'id' => $query->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> 
34
                '.$deleteLink;
35
            
36
                return $links;
37
            });
38
39
            return $datatables->make(true);
40
        }
41
        
42
        return view('backend.extra-field-default-value.index')->with('extraField', ExtraFieldService::find($extraFieldId));
43
    }
44
45
    public function create($extraFieldId)
46
    {
47
        return view('backend.extra-field-default-value.create')->with(array('extraField' =>  ExtraFieldService::find($extraFieldId)));
48
    }
49
50
    public function store(Request $request, $extraFieldId)
51
    {
52
        $result  = ExtraFieldService::createValue($request->all(), $extraFieldId);
53
        return ExtraFieldService::notificationRedirect(array('extra-field.values.index', $extraFieldId), $result, 'The extra field was inserted.');
54
    }
55
56
    public function edit($extraFieldId, $id)
57
    {
58
        return view('backend.extra-field-default-value.edit')->with(array('extraFieldDefaultValue' => ExtraFieldService::findValue($id)));
59
    }
60
61
    public function update(Request $request, $extraFieldId, $id)
62
    {
63
        $result  = ExtraFieldService::updateValueById($request->all(), $extraFieldId, $id);
64
        return ExtraFieldService::notificationRedirect(array('extra-field.values.index', $extraFieldId), $result, 'The extra field was updated.');
65
    }
66
67
    public function destroy($extraFieldId, $id)
68
    {
69
        $result  = ExtraFieldService::destroyValue($id);
70
71
        if ($result) {
72
            Notification::success('Extra field was deleted.');
73
            return redirect()->route('extra-field.values.index', $extraFieldId);
74
        }
75
    }
76
}
77