| Total Complexity | 9 |
| Total Lines | 109 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | class CustomerFileController extends Controller |
||
| 22 | { |
||
| 23 | use FileTrait; |
||
|
1 ignored issue
–
show
|
|||
| 24 | |||
| 25 | /** |
||
| 26 | * Store a file for a specific customer |
||
| 27 | */ |
||
| 28 | public function store(CustomerFileRequest $request) |
||
| 29 | { |
||
| 30 | // Make sure that the file information was stored in the users session |
||
| 31 | $this->checkForFile(); |
||
| 32 | $fileData = $request->session()->pull('new-file-upload'); |
||
| 33 | |||
| 34 | $cust = Customer::findOrFail($request->cust_id); |
||
| 35 | $cust_id = $cust->cust_id; |
||
| 36 | |||
| 37 | // If the equipment is shared, it must be assigned to the parent site |
||
| 38 | if($request->shared && $cust->parent_id > 0) |
||
| 39 | { |
||
| 40 | $cust_id = $cust->parent_id; |
||
| 41 | } |
||
| 42 | |||
| 43 | $newFile = CustomerFile::create([ |
||
| 44 | 'file_id' => $fileData[0]->file_id, |
||
| 45 | 'file_type_id' => CustomerFileType::where('description', $request->type)->first()->file_type_id, |
||
| 46 | 'cust_id' => $cust_id, |
||
| 47 | 'user_id' => $request->user()->user_id, |
||
| 48 | 'shared' => $request->shared, |
||
| 49 | 'name' => $request->name, |
||
| 50 | ]); |
||
| 51 | |||
| 52 | event(new CustomerFileAddedEvent(Customer::find($request->cust_id), $newFile)); |
||
|
1 ignored issue
–
show
|
|||
| 53 | return back()->with([ |
||
| 54 | 'message' => 'File Added', |
||
| 55 | 'type' => 'success', |
||
| 56 | ]); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Update the details for a customer uploaded file - not the file itself |
||
| 61 | */ |
||
| 62 | public function update(CustomerFileRequest $request, $id) |
||
| 85 | ]); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Delete a customer file |
||
| 90 | */ |
||
| 91 | public function destroy($id) |
||
| 92 | { |
||
| 93 | $this->authorize('delete', CustomerFile::class); |
||
| 94 | $file = CustomerFile::find($id); |
||
| 95 | $file->delete(); |
||
| 96 | |||
| 97 | event(new CustomerFileDeletedEvent(Customer::find($file->cust_id), $file)); |
||
|
2 ignored issues
–
show
|
|||
| 98 | return back()->with([ |
||
| 99 | 'message' => 'File Deleted', |
||
| 100 | 'type' => 'danger', |
||
| 101 | ]); |
||
| 102 | } |
||
| 103 | |||
| 104 | /* |
||
| 105 | * Restore a deleted file |
||
| 106 | */ |
||
| 107 | public function restore($id) |
||
| 115 | } |
||
| 116 | |||
| 117 | /* |
||
| 118 | * Permanently delete a file |
||
| 119 | */ |
||
| 120 | public function forceDelete($id) |
||
| 130 | } |
||
| 131 | } |
||
| 132 |