|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use Adminetic\Website\Contracts\FeatureRepositoryInterface; |
|
6
|
|
|
use Adminetic\Website\Http\Requests\FeatureRequest; |
|
7
|
|
|
use Adminetic\Website\Models\Admin\Feature; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
|
|
10
|
|
|
class FeatureRepository implements FeatureRepositoryInterface |
|
11
|
|
|
{ |
|
12
|
|
|
// Feature Index |
|
13
|
|
|
public function indexFeature() |
|
14
|
|
|
{ |
|
15
|
|
|
$features = config('adminetic.caching', true) |
|
16
|
|
|
? (Cache::has('features') ? Cache::get('features') : Cache::rememberForever('features', function () { |
|
17
|
|
|
return Feature::orderBy('position')->get(); |
|
18
|
|
|
})) |
|
19
|
|
|
: Feature::orderBy('position')->get(); |
|
20
|
|
|
|
|
21
|
|
|
return compact('features'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
// Feature Create |
|
25
|
|
|
public function createFeature() |
|
26
|
|
|
{ |
|
27
|
|
|
// |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// Feature Store |
|
31
|
|
|
public function storeFeature(FeatureRequest $request) |
|
32
|
|
|
{ |
|
33
|
|
|
$feature = Feature::create($request->validated()); |
|
34
|
|
|
$this->uploadImage($feature); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Feature Show |
|
38
|
|
|
public function showFeature(Feature $feature) |
|
39
|
|
|
{ |
|
40
|
|
|
return compact('feature'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Feature Edit |
|
44
|
|
|
public function editFeature(Feature $feature) |
|
45
|
|
|
{ |
|
46
|
|
|
return compact('feature'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Feature Update |
|
50
|
|
|
public function updateFeature(FeatureRequest $request, Feature $feature) |
|
51
|
|
|
{ |
|
52
|
|
|
$feature->update($request->validated()); |
|
53
|
|
|
$this->uploadImage($feature); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// Feature Destroy |
|
57
|
|
|
public function destroyFeature(Feature $feature) |
|
58
|
|
|
{ |
|
59
|
|
|
$feature->delete(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Upload Image |
|
63
|
|
|
private function uploadImage(Feature $feature) |
|
64
|
|
|
{ |
|
65
|
|
|
if (request()->has('image')) { |
|
66
|
|
|
$feature |
|
67
|
|
|
->addFromMediaLibraryRequest(request()->image) |
|
68
|
|
|
->toMediaCollection('image'); |
|
69
|
|
|
} |
|
70
|
|
|
if (request()->has('icon_image')) { |
|
71
|
|
|
$feature |
|
72
|
|
|
->addFromMediaLibraryRequest(request()->icon_image) |
|
73
|
|
|
->toMediaCollection('icon_image'); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|