1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\UploadFile\Http\Controllers\AdminApi; |
4
|
|
|
|
5
|
|
|
use BristolSU\Module\UploadFile\Events\DocumentUploaded; |
6
|
|
|
use BristolSU\Module\UploadFile\Http\Controllers\Controller; |
7
|
|
|
use BristolSU\Module\UploadFile\Http\Requests\AdminApi\FileController\StoreRequest; |
8
|
|
|
use BristolSU\Module\UploadFile\Models\File; |
9
|
|
|
use BristolSU\Support\Activity\Activity; |
10
|
|
|
use BristolSU\Support\Authentication\Contracts\Authentication; |
11
|
|
|
use BristolSU\Support\ModuleInstance\ModuleInstance; |
12
|
|
|
use Illuminate\Http\Request; |
13
|
|
|
use Illuminate\Support\Arr; |
14
|
|
|
|
15
|
|
|
class FileController extends Controller |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
|
18
|
3 |
|
public function index() |
|
|
|
|
19
|
|
|
{ |
20
|
3 |
|
$this->authorize('admin.file.index'); |
21
|
|
|
|
22
|
2 |
|
return File::forModuleInstance()->with(['statuses', 'comments'])->get(); |
23
|
|
|
} |
24
|
|
|
|
25
|
3 |
|
public function show(Activity $activity, ModuleInstance $moduleInstance, File $file) |
|
|
|
|
26
|
|
|
{ |
27
|
3 |
|
$this->authorize('admin.file.index'); |
28
|
|
|
|
29
|
2 |
|
return $file->load(['statuses', 'comments']); |
30
|
|
|
} |
31
|
|
|
|
32
|
6 |
|
public function store(StoreRequest $request, Authentication $authentication) |
|
|
|
|
33
|
|
|
{ |
34
|
6 |
|
$fileMetadata = collect(); |
35
|
|
|
|
36
|
6 |
|
foreach (Arr::wrap($request->file('file')) as $file) { |
37
|
|
|
|
38
|
6 |
|
$path = $file->store('uploadfile'); |
39
|
|
|
|
40
|
6 |
|
$fileMetadata->push($tempFileMeta = File::create([ |
|
|
|
|
41
|
6 |
|
'title' => $request->input('title'), |
42
|
6 |
|
'description' => $request->input('description'), |
43
|
6 |
|
'filename' => $file->getClientOriginalName(), |
44
|
6 |
|
'mime' => $file->getClientMimeType(), |
45
|
6 |
|
'path' => $path, |
46
|
6 |
|
'size' => $file->getSize(), |
47
|
6 |
|
'uploaded_by' => $authentication->getUser()->id(), |
48
|
6 |
|
'activity_instance_id' => $request->input('activity_instance_id') |
49
|
|
|
])); |
|
|
|
|
50
|
|
|
|
51
|
6 |
|
event(new DocumentUploaded($tempFileMeta)); |
52
|
|
|
} |
53
|
|
|
|
54
|
6 |
|
return $fileMetadata; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |