Completed
Push — development ( 307e1e...b67852 )
by Ashutosh
09:13
created

SlaController::create()   A

Complexity

Conditions 4
Paths 14

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 21
rs 9.7666
c 0
b 0
f 0
cc 4
nc 14
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Licence;
4
5
use App\Http\Controllers\Controller;
6
use App\Model\licence\Licence;
7
use App\Model\Licence\LicencedOrganization;
8
use App\Model\licence\Sla;
9
use App\Model\licence\SlaServiceRelation;
10
use App\Model\Product\Service;
11
use App\Organization;
12
use Illuminate\Http\Request;
13
14
class SlaController extends Controller
15
{
16
    public $sla;
17
    public $slaServiceRelation;
18
    public $service;
19
    public $licence;
20
    public $organization;
21
    public $licencedOrganization;
22
23
    public function __construct()
24
    {
25
        $this->middleware('auth');
26
        $this->middleware('service.provider', ['only' => ['create', 'store', 'edit', 'update']]);
27
        //$this->middleware('admin');
28
        $cart = new \App\Http\Controllers\Front\CheckoutController();
29
        $auth = ''; //$cart->GetXdeskAuthOrganization();
30
        $this->org = $auth;
31
32
        $sla = new Sla();
33
        $this->sla = $sla;
34
35
        $slaServiceRelation = new SlaServiceRelation();
36
        $this->slaServiceRelation = $slaServiceRelation;
37
38
        $service = new Service();
39
        $this->service = $service;
40
41
        $licence = new Licence();
42
        $this->licence = $licence;
43
44
        $organization = new Organization();
45
        $this->organization = $organization;
46
47
        $licencedOrganization = new LicencedOrganization();
48
        $this->licencedOrganization = $licencedOrganization;
49
    }
50
51
    public function index()
52
    {
53
        try {
54
            return view('themes.default1.sla.index');
55
        } catch (\Exception $ex) {
56
            return redirect()->back()->with('fails', $ex->getMessage());
57
        }
58
    }
59
60
61
62
    public function update($id, Request $request)
63
    {
64
        try {
65
            $service = $this->slaServiceRelation->where('sla_id', $id)->first();
66
            $service->delete();
67
68
            $service_id = $request->input('service');
69
            $sla = $this->sla->where('id', $id)->first();
70
            $sla->fill($request->input())->save();
71
            $this->slaServiceRelation->create(['sla_id' => $id, 'service_id' => $service_id]);
72
73
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
74
        } catch (\Exception $ex) {
75
            return redirect()->back()->with('fails', $ex->getMessage());
76
        }
77
    }
78
}
79