|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use Adminetic\Website\Contracts\BlockRepositoryInterface; |
|
6
|
|
|
use Adminetic\Website\Http\Requests\BlockRequest; |
|
|
|
|
|
|
7
|
|
|
use Adminetic\Website\Models\Admin\Block; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
use Intervention\Image\Facades\Image; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class BlockRepository implements BlockRepositoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
// Block Index |
|
14
|
|
|
public function indexBlock() |
|
15
|
|
|
{ |
|
16
|
|
|
$blocks = config('adminetic.caching', true) |
|
17
|
|
|
? (Cache::has('blocks') ? Cache::get('blocks') : Cache::rememberForever('blocks', function () { |
|
18
|
|
|
return Block::orderBy('position')->get(); |
|
19
|
|
|
})) |
|
20
|
|
|
: Block::orderBy('position')->get(); |
|
21
|
|
|
|
|
22
|
|
|
return compact('blocks'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// Block Create |
|
26
|
|
|
public function createBlock() |
|
27
|
|
|
{ |
|
28
|
|
|
$block_domains = Block::latest()->pluck('page')->toArray(); |
|
29
|
|
|
$versions = Block::latest()->pluck('version')->toArray(); |
|
30
|
|
|
$block_types = Block::latest()->pluck('type')->toArray(); |
|
31
|
|
|
|
|
32
|
|
|
return compact('block_domains', 'versions', 'block_types'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Block Store |
|
36
|
|
|
public function storeBlock(BlockRequest $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$block = Block::create($request->validated()); |
|
39
|
|
|
$this->versionActivationControl($block); |
|
40
|
|
|
$this->uploadImage($block); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Block Show |
|
44
|
|
|
public function showBlock(Block $block) |
|
45
|
|
|
{ |
|
46
|
|
|
return compact('block'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Block Edit |
|
50
|
|
|
public function editBlock(Block $block) |
|
51
|
|
|
{ |
|
52
|
|
|
$block_domains = Block::latest()->pluck('page')->toArray(); |
|
53
|
|
|
$versions = Block::latest()->pluck('version')->toArray(); |
|
54
|
|
|
$block_types = Block::latest()->pluck('type')->toArray(); |
|
55
|
|
|
|
|
56
|
|
|
return compact('block', 'block_domains', 'versions', 'block_types'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Block Update |
|
60
|
|
|
public function updateBlock(BlockRequest $request, Block $block) |
|
61
|
|
|
{ |
|
62
|
|
|
$block->update($request->validated()); |
|
63
|
|
|
$this->versionActivationControl($block); |
|
64
|
|
|
$this->uploadImage($block); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// Block Destroy |
|
68
|
|
|
public function destroyBlock(Block $block) |
|
69
|
|
|
{ |
|
70
|
|
|
isset($block->image) ? deleteImage($block->image) : ''; |
|
|
|
|
|
|
71
|
|
|
$block->delete(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// Image Upload |
|
75
|
|
|
protected function uploadImage(Block $block) |
|
76
|
|
|
{ |
|
77
|
|
|
if (request()->has('image')) { |
|
78
|
|
|
$block->update([ |
|
79
|
|
|
'image' => request()->image->store('website/block', 'public'), |
|
80
|
|
|
]); |
|
81
|
|
|
$image = Image::make(request()->file('image')->getRealPath()); |
|
82
|
|
|
$image->save(public_path('storage/' . $block->image)); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
// Version Activation Control |
|
87
|
|
|
protected function versionActivationControl(Block $block) |
|
88
|
|
|
{ |
|
89
|
|
|
$blocks = Block::where([ |
|
90
|
|
|
['id', '<>', $block->id], |
|
91
|
|
|
['type', '=', $block->type], |
|
92
|
|
|
['theme', '=', $block->theme], |
|
93
|
|
|
])->pluck('id')->toArray(); |
|
94
|
|
|
|
|
95
|
|
|
if ($block->active) { |
|
96
|
|
|
Block::whereIn('id', $blocks)->update(['active' => 0]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths