1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ShopController |
5
|
|
|
* |
6
|
|
|
* This is the controller of the shops |
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 DataTables; |
14
|
|
|
use Form; |
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService; |
16
|
|
|
|
17
|
|
|
class ShopController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function index(Request $request) |
20
|
|
|
{ |
21
|
|
|
if ($request->wantsJson()) { |
22
|
|
|
|
23
|
|
|
$query = ShopService::getModel()->select(['id', 'title', 'url', 'logo_file_name']); |
24
|
|
|
|
25
|
|
|
$datatables = DataTables::of($query) |
26
|
|
|
|
27
|
|
|
->addColumn('action', function ($query) { |
28
|
|
|
$deleteLink = Form::deleteajax(url()->route('shop.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
29
|
|
|
$links = '<a href="'.url()->route('shop.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
30
|
|
|
return $links; |
31
|
|
|
}) |
32
|
|
|
|
33
|
|
|
->addColumn('image', function ($query) { |
34
|
|
|
if ($query->logo_file_name) { |
35
|
|
|
return '<img src="/files/shop/'.$query->id.'/'.$query->logo_file_name.'" />'; |
36
|
|
|
} |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
return $datatables->rawColumns(['image', 'action'])->make(true); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return view('backend.shop.index')->with('shop', ShopService::selectAll()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function create() |
46
|
|
|
{ |
47
|
|
|
return view('backend.shop.create'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function store(Request $request) |
51
|
|
|
{ |
52
|
|
|
$result = ShopService::create($request->all()); |
53
|
|
|
return ShopService::notificationRedirect('shop.index', $result, 'The shop was inserted.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function edit($shopId) |
57
|
|
|
{ |
58
|
|
|
return view('backend.shop.edit')->with(array('shop' => ShopService::find($shopId))); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function update(Request $request, $shopId) |
62
|
|
|
{ |
63
|
|
|
$result = ShopService::updateById($request->all(), $shopId); |
64
|
|
|
return ShopService::notificationRedirect('shop.index', $result, 'The shop was updated.'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function destroy($shopId) |
68
|
|
|
{ |
69
|
|
|
$result = ShopService::destroy($shopId); |
70
|
|
|
|
71
|
|
|
if ($result) { |
72
|
|
|
flash('The shop was deleted.'); |
73
|
|
|
return redirect()->route('shop.index'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |