Passed
Push — master ( 2232db...f4b030 )
by Matthijs
20:23 queued 14:47
created

NewsGroupController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * NewsGroupController
5
 *
6
 * This is the controller of the newss of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Illuminate\Http\Request;
13
use Notification;
14
15
use Hideyo\Ecommerce\Framework\Services\News\NewsFacade as NewsService;
16
17
class NewsGroupController extends Controller
18
{
19
    public function index(Request $request)
20
    {
21
        if ($request->wantsJson()) {
22
23
            $query = NewsService::getGroupModel()->select(
24
                [
25
                
26
                'id',
27
                'title']
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)
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...
31
            ->addColumn('action', function ($query) {
32
                $deleteLink = \Form::deleteajax(url()->route('news-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
33
                $links = '<a href="'.url()->route('news-group.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
34
            
35
                return $links;
36
            });
37
38
            return $datatables->make(true);
39
40
        }
41
        
42
        return view('backend.news_group.index')->with('newsGroup', NewsService::selectAll());
43
    }
44
45
    public function create()
46
    {
47
        return view('backend.news_group.create')->with(array());
48
    }
49
50
    public function store(Request $request)
51
    {
52
        $result  = NewsService::createGroup($request->all());
53
        return NewsService::notificationRedirect('news-group.index', $result, 'The news group was inserted.');
54
    }
55
56
    public function edit($newsGroupId)
57
    {
58
        return view('backend.news_group.edit')->with(array('newsGroup' => NewsService::findGroup($newsGroupId)));
59
    }
60
61
    public function update(Request $request, $newsGroupId)
62
    {
63
        $result  = NewsService::updateGroupById($request->all(), $newsGroupId);
64
        return NewsService::notificationRedirect('news-group.index', $result, 'The news group was updated.');
65
    }
66
67
    public function destroy($newsGroupId)
68
    {
69
        $result  = NewsService::destroyGroup($newsGroupId);
70
71
        if ($result) {
72
            Notification::success('The news group was deleted.');
73
            return redirect()->route('news-group.index');
74
        }
75
    }
76
}
77