1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
/** |
3
|
|
|
* BrandController |
4
|
|
|
* |
5
|
|
|
* This is the controller of the brands of the shop |
6
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
7
|
|
|
* @version 0.1 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
use App\Http\Controllers\Controller; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Form; |
13
|
|
|
use DataTables; |
14
|
|
|
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\Brand\BrandFacade as BrandService; |
16
|
|
|
|
17
|
|
|
class BrandController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function index(Request $request) |
20
|
|
|
{ |
21
|
|
|
if ($request->wantsJson()) { |
22
|
|
|
$brand = BrandService::getModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$datatables = DataTables::of($brand)->addColumn('action', function ($query) { |
25
|
|
|
$deleteLink = Form::deleteajax(url()->route('brand.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'), $query->title); |
26
|
|
|
$links = '<a href="'.url()->route('brand.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
27
|
|
|
|
28
|
|
|
return $links; |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
return $datatables->make(true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return view('backend.brand.index')->with('brand', BrandService::selectAll()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function create() |
38
|
|
|
{ |
39
|
|
|
return view('backend.brand.create')->with(array()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function store(Request $request) |
43
|
|
|
{ |
44
|
|
|
$result = BrandService::create($request->all()); |
45
|
|
|
return BrandService::notificationRedirect('brand.index', $result, 'The brand was inserted.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function edit($brandId) |
49
|
|
|
{ |
50
|
|
|
return view('backend.brand.edit')->with(array('brand' => BrandService::find($brandId))); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function update(Request $request, $brandId) |
54
|
|
|
{ |
55
|
|
|
$result = BrandService::updateById($request->all(), $brandId); |
56
|
|
|
return BrandService::notificationRedirect('brand.index', $result, 'The brand was updated.'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function destroy($brandId) |
60
|
|
|
{ |
61
|
|
|
$result = BrandService::destroy($brandId); |
62
|
|
|
if ($result) { |
63
|
|
|
flash('The brand was deleted.'); |
64
|
|
|
return redirect()->route('brand.index'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|