|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xetaravel\Http\Controllers\Admin\Shop; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\RedirectResponse; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Illuminate\View\View; |
|
9
|
|
|
use Xetaio\Mentions\Parser\MentionParser; |
|
10
|
|
|
use Xetaravel\Http\Controllers\Admin\Controller; |
|
11
|
|
|
use Xetaravel\Models\ShopItem; |
|
12
|
|
|
use Xetaravel\Models\ShopCategory; |
|
13
|
|
|
use Xetaravel\Models\Repositories\ShopItemRepository; |
|
14
|
|
|
use Xetaravel\Models\Validators\ShopItemValidator; |
|
15
|
|
|
|
|
16
|
|
|
class ItemController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct(); |
|
24
|
|
|
|
|
25
|
|
|
$this->breadcrumbs->addCrumb('Shop', route('admin.shop.item.index')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Show all articles. |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Illuminate\View\View |
|
32
|
|
|
*/ |
|
33
|
|
|
public function index(): View |
|
34
|
|
|
{ |
|
35
|
|
|
$this->breadcrumbs->addCrumb('Manage Articles', route('admin.blog.article.index')); |
|
36
|
|
|
|
|
37
|
|
|
return view('Admin::Shop.item.index', ['breadcrumbs' => $this->breadcrumbs]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Show the item create form. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Illuminate\View\View |
|
44
|
|
|
*/ |
|
45
|
|
|
public function showCreateForm(): View |
|
46
|
|
|
{ |
|
47
|
|
|
$categories = ShopCategory::pluck('title', 'id'); |
|
48
|
|
|
|
|
49
|
|
|
$breadcrumbs = $this->breadcrumbs |
|
50
|
|
|
->addCrumb('Manage Items', route('admin.shop.item.index')) |
|
51
|
|
|
->addCrumb("Create", route('admin.shop.item.create')); |
|
52
|
|
|
|
|
53
|
|
|
return view('Admin::Shop.item.create', compact('categories', 'breadcrumbs')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Handle an article create request for the application. |
|
58
|
|
|
* |
|
59
|
|
|
* @param \Illuminate\Http\Request $request |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
62
|
|
|
*/ |
|
63
|
|
|
public function create(Request $request): RedirectResponse |
|
64
|
|
|
{ |
|
65
|
|
|
ShopItemValidator::create($request->all())->validate(); |
|
66
|
|
|
$item = ShopItemRepository::create($request->all()); |
|
67
|
|
|
|
|
68
|
|
|
$item->save(); |
|
69
|
|
|
|
|
70
|
|
|
// Default icon for the article. |
|
71
|
|
|
$icon = public_path('images/shop/default_icon.svg'); |
|
72
|
|
|
|
|
73
|
|
|
if (!is_null($request->file('item'))) { |
|
74
|
|
|
$icon = $request->file('item'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$item->clearMediaCollection('item'); |
|
78
|
|
|
$item->addMedia($icon) |
|
|
|
|
|
|
79
|
|
|
->preservingOriginal() |
|
80
|
|
|
->setName(substr(md5($item->slug), 0, 10)) |
|
81
|
|
|
->setFileName( |
|
82
|
|
|
substr(md5($item->slug), 0, 10) . '.svg' |
|
83
|
|
|
) |
|
84
|
|
|
->toMediaCollection('item'); |
|
85
|
|
|
|
|
86
|
|
|
return redirect() |
|
87
|
|
|
->route('admin.shop.item.index') |
|
88
|
|
|
->with('success', 'Your item has been created successfully !'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|