1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Http\Requests\Admin\CreateUpdatePriceList; |
7
|
|
|
use App\PriceCategory; |
8
|
|
|
use App\PriceList; |
9
|
|
|
|
10
|
|
|
class PriceListController extends Controller |
11
|
|
|
{ |
12
|
|
|
public function create(CreateUpdatePriceList $request) |
13
|
|
|
{ |
14
|
|
|
$validated = $request->validated(); |
15
|
|
|
$list = PriceList::create([ |
16
|
|
|
'name' => $validated['name'] |
17
|
|
|
]); |
18
|
|
|
// On successfull creation redirect the browser to the object |
19
|
|
|
return redirect() |
20
|
|
|
->route('admin.dependencies.prices.list.get', $list) |
21
|
|
|
->with('status', 'Created ' . $list->name . '!'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function get(PriceList $list) |
25
|
|
|
{ |
26
|
|
|
return view('admin.dependencies.manage-price-list', [ |
27
|
|
|
'list' => $list, |
28
|
|
|
'categories' => PriceCategory::all() |
29
|
|
|
]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function update(PriceList $list, CreateUpdatePriceList $request) |
33
|
|
|
{ |
34
|
|
|
$validated = $request->validated(); |
35
|
|
|
|
36
|
|
|
// Set the new submitted (direct) list properties |
37
|
|
|
$list->name = $validated['name']; |
38
|
|
|
$list->save(); |
39
|
|
|
|
40
|
|
|
// Detach all categories from the list |
41
|
|
|
$list->categories()->detach(); |
42
|
|
|
|
43
|
|
|
// Attach only the given categories to the list |
44
|
|
|
$list->categories()->attach($validated['categories']); |
45
|
|
|
|
46
|
|
|
// On successfull update redirect the browser to the list object |
47
|
|
|
return redirect() |
48
|
|
|
->route('admin.dependencies.prices.list.get', $list) |
49
|
|
|
->with('status', 'Update successfull!'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function delete(PriceList $list) |
53
|
|
|
{ |
54
|
|
|
$list->categories()->detach(); |
55
|
|
|
$list->delete(); |
56
|
|
|
|
57
|
|
|
// On successfull deletion redirect the browser to the overview |
58
|
|
|
return redirect() |
59
|
|
|
->route('admin.dependencies.dashboard') |
60
|
|
|
->with('status', 'Deleted list successfull!'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|