1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Http\Requests\Customers\CustomerFileRequest; |
7
|
|
|
use App\Models\CustomerFile; |
8
|
|
|
use App\Models\CustomerFileType; |
9
|
|
|
use App\Models\FileUploads; |
10
|
|
|
use App\Traits\FileTrait; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
use Illuminate\Support\Facades\Log; |
13
|
|
|
|
14
|
|
|
class CustomerFilesController extends Controller |
15
|
|
|
{ |
16
|
|
|
use FileTrait; |
17
|
|
|
|
18
|
|
|
protected $disk; |
19
|
|
|
|
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
$this->disk = 'customers'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Upload a new file |
27
|
|
|
*/ |
28
|
|
|
public function store(CustomerFileRequest $request) |
29
|
|
|
{ |
30
|
|
|
// Process the chunk of file being uploaded |
31
|
|
|
$status = $this->getChunk($request, $this->disk, $request->cust_id); |
32
|
|
|
|
33
|
|
|
// If the file upload is completed, save to database |
34
|
|
|
if($status['done'] === 100) |
35
|
|
|
{ |
36
|
|
|
$newFile = FileUploads::create([ |
37
|
|
|
'disk' => $this->disk, |
38
|
|
|
'folder' => $request->cust_id, |
39
|
|
|
'file_name' => $status['filename'], |
40
|
|
|
'public' => false, |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
CustomerFile::create([ |
44
|
|
|
'file_id' => $newFile->file_id, |
45
|
|
|
'file_type_id' => CustomerFileType::where('description', $request->type)->first()->file_type_id, |
46
|
|
|
'cust_id' => $request->cust_id, |
47
|
|
|
'user_id' => $request->user()->user_id, |
48
|
|
|
'shared' => filter_var($request->shared, FILTER_VALIDATE_BOOL), |
49
|
|
|
'name' => $request->name, |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
return response()->noContent(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// If upload is still in progress, send current status of upload |
56
|
|
|
return response($status); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Ajax call to get the files for a specific customer |
61
|
|
|
*/ |
62
|
|
|
public function show($id) |
63
|
|
|
{ |
64
|
|
|
return CustomerFile::where('cust_id', $id)->with('FileUpload')->get(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Show the form for editing the specified resource. |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
// public function edit($id) |
72
|
|
|
// { |
73
|
|
|
// // |
74
|
|
|
// } |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Update the specified resource in storage. |
78
|
|
|
* |
79
|
|
|
*/ |
80
|
|
|
// public function update(Request $request, $id) |
81
|
|
|
// { |
82
|
|
|
// // |
83
|
|
|
// } |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Delete a customer File |
87
|
|
|
*/ |
88
|
|
|
public function destroy($id) |
89
|
|
|
{ |
90
|
|
|
CustomerFile::find($id)->delete(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|