SendingMethodController::destroy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
rs 10
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 Form;
18
use DataTables;
19
20
class SendingMethodController extends Controller
21
{
22
    public function index(Request $request)
23
    {
24
        if ($request->wantsJson()) {
25
            $query = SendingMethodService::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...
26
27
            $datatables = DataTables::of($query)->addColumn('action', function ($query) {
28
                $deleteLink = Form::deleteajax(url()->route('sending-method.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger'), $query->title);
29
                $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;
30
            
31
32
                return $links;
33
            });
34
35
            return $datatables->make(true);
36
        }
37
        
38
        return view('backend.sending_method.index')->with('sendingMethod', SendingMethodService::selectAll());
39
    }
40
41
    public function create()
42
    {
43
        return view('backend.sending_method.create')->with(array(
44
            'taxRates' => TaxRateService::selectAll()->pluck('title', 'id'),
45
            'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id')
46
        ));
47
    }
48
49
    public function store(Request $request)
50
    {
51
        $result  = SendingMethodService::create($request->all());
52
        return SendingMethodService::notificationRedirect('sending-method.index', $result, 'The sending method was inserted.');
53
    }
54
55
    public function edit($sendingMethodId)
56
    {    
57
        return view('backend.sending_method.edit')->with(
58
            array(
59
                'taxRates'          => TaxRateService::selectAll()->pluck('title', 'id'),
60
                'sendingMethod'     => SendingMethodService::find($sendingMethodId),
61
                'paymentMethods'    => PaymentMethodService::selectAll()->pluck('title', 'id'),
62
            )
63
        );
64
    }
65
66
    public function update(Request $request, $sendingMethodId)
67
    {
68
        $result  = SendingMethodService::updateById($request->all(), $sendingMethodId);
69
        return SendingMethodService::notificationRedirect('sending-method.index', $result, 'The sending method was updated.');
70
    }
71
72
    public function destroy($sendingMethodId)
73
    {
74
        $result  = SendingMethodService::destroy($sendingMethodId);
75
76
        if ($result) {
77
            flash('The sending method was deleted.');
78
            return redirect()->route('sending-method.index');
79
        }
80
    }
81
}
82