Changeset 4521f25 for app/Http


Ignore:
Timestamp:
10/31/21 22:09:08 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
master
Children:
8fdb18e
Parents:
e78295c
Message:

edited blades

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/FoldersController.php

    re78295c r4521f25  
    44
    55use App\Helpers\Alert;
     6use App\Http\Requests\Dashboard\FileRequest;
    67use App\Http\Requests\Dashboard\FolderRequest;
    78use App\Http\Requests\Dashboard\FileNameRequest;
     
    186187    }
    187188
     189    public function uploadFiles(FileRequest $request, $id)
     190    {
     191        $file = new File();
     192
     193        $folder = Folder::findOrFail($id);
     194
     195        $location = $folder->location;
     196
     197        $users = User::all();
     198
     199        if ($request->has('file_item')) {
     200            foreach ($request->file_item as $file) {
     201                $fileName = $file->getClientOriginalName();
     202
     203                if(File::where(['folder_id' => $folder->id, 'name' => $fileName])->count() > 0) {
     204                    Alert::flash("The uploaded file already exists", "error");
     205
     206                    return redirect()->back();
     207                }
     208
     209                $file->storeAs($location . DIRECTORY_SEPARATOR, $fileName);
     210                $newFile = new File();
     211                $newFile->name = $fileName;
     212                $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
     213                //$newFile->folder()->associate($folder);
     214                $newFile->folder()->associate($folder);
     215                $newFile->folder()->increment('no_of_files');
     216                $newFile->save();
     217            }
     218
     219            Alert::flash("New files added successfully");
     220
     221            return redirect()->back();
     222        }
     223        else {
     224            Alert::flash("No files were uploaded", "error");
     225
     226            return redirect()->back();
     227        }
     228    }
     229
    188230    public function destroy($id)
    189231    {
Note: See TracChangeset for help on using the changeset viewer.