1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* NewsController |
5
|
|
|
* |
6
|
|
|
* This is the controller of the news 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
|
|
|
use Datatables; |
|
|
|
|
15
|
|
|
use Form; |
16
|
|
|
|
17
|
|
|
use Hideyo\Ecommerce\Framework\Services\News\NewsFacade as NewsService; |
18
|
|
|
|
19
|
|
|
class NewsController extends Controller |
20
|
|
|
{ |
21
|
|
|
public function index(Request $request) |
22
|
|
|
{ |
23
|
|
|
if ($request->wantsJson()) { |
24
|
|
|
|
25
|
|
|
$query = NewsService::getModel()->select( |
26
|
|
|
[ |
27
|
|
|
NewsService::getModel()->getTable().'.id', |
28
|
|
|
NewsService::getModel()->getTable().'.title', |
29
|
|
|
NewsService::getGroupModel()->getTable().'.title as newsgroup'] |
30
|
|
|
)->where(NewsService::getModel()->getTable().'.shop_id', '=', auth('hideyobackend')->user()->selected_shop_id) |
|
|
|
|
31
|
|
|
->with(array('newsGroup')) ->leftJoin(NewsService::getGroupModel()->getTable(), NewsService::getGroupModel()->getTable().'.id', '=', 'news_group_id'); |
32
|
|
|
|
33
|
|
|
$datatables = Datatables::of($query) |
34
|
|
|
->filterColumn('title', function ($query, $keyword) { |
35
|
|
|
|
36
|
|
|
$query->where( |
37
|
|
|
function ($query) use ($keyword) { |
38
|
|
|
$query->whereRaw("news.title like ?", ["%{$keyword}%"]); |
39
|
|
|
; |
40
|
|
|
} |
41
|
|
|
); |
42
|
|
|
}) |
43
|
|
|
->addColumn('newsgroup', function ($query) { |
44
|
|
|
return $query->newstitle; |
45
|
|
|
}) |
46
|
|
|
|
47
|
|
|
->addColumn('action', function ($query) { |
48
|
|
|
$deleteLink = Form::deleteajax(url()->route('news.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
49
|
|
|
$links = '<a href="'.url()->route('news.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
50
|
|
|
|
51
|
|
|
return $links; |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
return $datatables->make(true); |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return view('backend.news.index')->with('news', NewsService::selectAll()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function create() |
62
|
|
|
{ |
63
|
|
|
return view('backend.news.create')->with(array('groups' => NewsService::selectAllGroups()->pluck('title', 'id')->toArray())); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function store(Request $request) |
67
|
|
|
{ |
68
|
|
|
$result = NewsService::create($request->all()); |
69
|
|
|
return NewsService::notificationRedirect('news.index', $result, 'The news item was inserted.'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function edit($newsId) |
73
|
|
|
{ |
74
|
|
|
return view('backend.news.edit')->with(array('news' => NewsService::find($newsId), 'groups' => NewsService::selectAllGroups()->pluck('title', 'id')->toArray())); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function reDirectoryAllImages() |
78
|
|
|
{ |
79
|
|
|
$this->newsImage->reDirectoryAllImagesByShopId(auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return redirect()->route('news.index'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function refactorAllImages() |
85
|
|
|
{ |
86
|
|
|
$this->newsImage->refactorAllImagesByShopId(auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
87
|
|
|
|
88
|
|
|
return redirect()->route('news.index'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function update(Request $request, $newsId) |
92
|
|
|
{ |
93
|
|
|
$result = NewsService::updateById($request->all(), $newsId); |
94
|
|
|
return NewsService::notificationRedirect('news.index', $result, 'The news item was inserted.'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function destroy($newsId) |
98
|
|
|
{ |
99
|
|
|
$result = NewsService::destroy($newsId); |
100
|
|
|
|
101
|
|
|
if ($result) { |
102
|
|
|
Notification::success('The news was deleted.'); |
103
|
|
|
return redirect()->route('news.index'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths