-
Notifications
You must be signed in to change notification settings - Fork 554
/
FileRepository.php
44 lines (36 loc) · 1.11 KB
/
FileRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace A17\Twill\Repositories;
use A17\Twill\Models\File;
use A17\Twill\Repositories\Behaviors\HandleTags;
use Storage;
class FileRepository extends ModuleRepository
{
use HandleTags;
public function __construct(File $model)
{
$this->model = $model;
}
public function filter($query, array $scopes = [])
{
$this->searchIn($query, $scopes, 'search', ['filename']);
return parent::filter($query, $scopes);
}
public function delete($id)
{
if (($object = $this->model->find($id)) != null) {
if ($object->canDeleteSafely()) {
$storageId = $object->uuid;
if ($object->delete() && config('twill.file_library.cascade_delete')) {
Storage::disk(config('twill.file_library.disk'))->delete($storageId);
}
}
}
}
public function prepareFieldsBeforeCreate($fields)
{
if (!isset($fields['size'])) {
$fields['size'] = Storage::disk(config('twill.file_library.disk'))->size($fields['uuid']);
}
return $fields;
}
}