Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YuraLons's avatar

Upload Files in storage

There is a table house. It has four columns (where the path to the downloaded file should be saved). I tried to download one file in the controller for the test, but it did not appear in the database

 $this->validate($request, [
                      'passport' => 'required'
        ]);

        $homes = Houses::query()->create([
                
                'passport' => $request->get('passport')
            ]
        );
     
        $request->validate([
            'file' => 'required|mimes:docs,txt,doc,xls,pdf,docx, docm,rtf,xps,xml|max:4098'
        ]);

        $fileModel = new File;

        if ($request->file()) {
            $fileName = time() . '_' . $request->file - getClientOriginalName();
            $filePath = $request->file('passport')->storeAs('passport_house', $fileName, 'public');

            $fileModel->name = time() . '_' . $request->file->getClientOriginalName();
            $fileModel->file_path = '/storage/' . $filePath;
            $fileModel->save();
        }


        return redirect()->route('homes.index');
    }

How do I fix this?

0 likes
0 replies

Please or to participate in this conversation.