Passed
Push — master ( f4b030...a2b3af )
by Matthijs
22:06 queued 15:53
created

SendingMethodController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * SendingMethodController
5
 *
6
 * This is the controller of the sending methods 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\SendingMethod\SendingMethodFacade as SendingMethodService;
14
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService;
15
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;
16
use Illuminate\Http\Request;
17
use Notification;
18
use Form;
19
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...
20
21
class SendingMethodController extends Controller
22
{
23
    public function index(Request $request)
24
    {
25
        if ($request->wantsJson()) {
26
            $query = SendingMethodService::getModel()
27
28
            ->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...
29
30
            $datatables = Datatables::of($query)->addColumn('action', function ($query) {
31
                $deleteLink = Form::deleteajax(url()->route('sending-method.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger'), $query->title);
32
                $links = '<a href="'.url()->route('sending-method.country-prices.index', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Country prices ('.$query->countryPrices()->count().')</a>  <a href="/admin/sending-method/'.$query->id.'/edit" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
33
            
34
35
                return $links;
36
            });
37
38
            return $datatables->make(true);
39
        }
40
        
41
        return view('backend.sending_method.index')->with('sendingMethod', SendingMethodService::selectAll());
42
    }
43
44
    public function create()
45
    {
46
        return view('backend.sending_method.create')->with(array(
47
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
48
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id')
49
        ));
50
    }
51
52
    public function store(Request $request)
53
    {
54
        $result  = SendingMethodService::create($request->all());
55
        return SendingMethodService::notificationRedirect('sending-method.index', $result, 'The sending method was inserted.');
56
    }
57
58
    public function edit($sendingMethodId)
59
    {    
60
        return view('backend.sending_method.edit')->with(
61
            array(
62
                'taxRates'          => TaxRateService::selectAll()->pluck('title', 'id'),
63
                'sendingMethod'     => SendingMethodService::find($sendingMethodId),
64
                'paymentMethods'    => PaymentMethodService::selectAll()->pluck('title', 'id'),
65
            )
66
        );
67
    }
68
69
    public function update(Request $request, $sendingMethodId)
70
    {
71
        $result  = SendingMethodService::updateById($request->all(), $sendingMethodId);
72
        return SendingMethodService::notificationRedirect('sending-method.index', $result, 'The sending method was updated.');
73
    }
74
75
    public function destroy($sendingMethodId)
76
    {
77
        $result  = SendingMethodService::destroy($sendingMethodId);
78
79
        if ($result) {
80
            Notification::success('The sending method was deleted.');
81
            return redirect()->route('sending-method.index');
82
        }
83
    }
84
}
85