ContentController::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 2
b 0
f 1
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php namespace App\Http\Controllers\Backend;
2
3
4
use App\Http\Controllers\Controller;
5
6
/**
7
 * ContentController
8
 *
9
 * This is the controller of the contents of the shop
10
 * @author Matthijs Neijenhuijs <[email protected]>
11
 * @version 0.1
12
 */
13
14
use Hideyo\Ecommerce\Framework\Services\Content\ContentFacade as ContentService;
15
use Illuminate\Http\Request;
16
use Form;
17
use DataTables;
18
19
class ContentController extends Controller
20
{
21
    public function index(Request $request)
22
    {
23
        if ($request->wantsJson()) {
24
            $content = ContentService::getModel()->select(
25
                [ContentService::getModel()->getTable().'.id',
26
                ContentService::getModel()->getTable().'.title', ContentService::getModel()->getTable().'.content_group_id', ContentService::getGroupModel()->getTable().'.title as contenttitle']
27
            )->where(ContentService::getModel()->getTable().'.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...
28
29
            ->with(array('contentGroup'))        ->leftJoin(ContentService::getGroupModel()->getTable(), ContentService::getGroupModel()->getTable().'.id', '=', ContentService::getModel()->getTable().'.content_group_id');
30
            
31
            $datatables = DataTables::of($content)
32
33
            ->filterColumn('title', function ($query, $keyword) {
34
                $query->whereRaw("content.title like ?", ["%{$keyword}%"]);
35
            })
36
            ->addColumn('contentgroup', function ($content) {
37
                return $content->contenttitle;
38
            })
39
            ->addColumn('action', function ($content) {
40
                $deleteLink = Form::deleteajax(url()->route('content.destroy', $content->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
41
                $links = '<a href="'.url()->route('content.edit', $content->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
42
            
43
                return $links;
44
            });
45
46
            return $datatables->make(true);
47
        }
48
        
49
        return view('backend.content.index')->with('content', ContentService::selectAll());
50
    }
51
52
    public function create()
53
    {
54
        return view('backend.content.create')->with(array('groups' => ContentService::selectAllGroups()->pluck('title', 'id')->toArray()));
55
    }
56
57
    public function store(Request $request)
58
    {
59
        $result  = ContentService::create($request->all());
60
        return ContentService::notificationRedirect('content.index', $result, 'The content was inserted.');
61
    }
62
63
    public function edit($contentId)
64
    {
65
        return view('backend.content.edit')->with(array('content' => ContentService::find($contentId), 'groups' => ContentService::selectAllGroups()->pluck('title', 'id')->toArray()));
66
    }
67
68
    public function update(Request $request, $contentId)
69
    {
70
        $result  = ContentService::updateById($request->all(), $contentId);
71
        return ContentService::notificationRedirect('content.index', $result, 'The content was updated.');
72
    }
73
74
    public function destroy(Request $request, $contentId)
75
    {
76
        $result  = ContentService::destroy($contentId);
77
78
        if ($result) {
79
            flash('The content was deleted.');
80
            return redirect()->route('content.index');
81
        }
82
    }
83
}