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); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$datatables = \Datatables::of($query) |
|
|
|
|
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
|
|
|
|