lily90's avatar

Problem with upload file in database

How do you store file in database? I'm trying to store my file in database but I got error message with fail upload.

My path folder application also are not created.

One of the method that I have tried

public function store(Request $request)
    {
           $this->validate($request,[
           
            'proposal'=>'required|mimes:doc,docx,pdf |max:2048' 
        ]);

        //handle the file upload
        if($request->hasFile('proposal')){   // to check if user has opted to upload the file
        
            // get filename with extention
            $filenameWithExt = $request->file('proposal')->getClientOriginalName();

            //get just filename
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            //get ext (extention)
            $extension =$request->file('proposal')->getClientOriginalExtension();
            //filename to store
            $fileNameToStore = $filename .'_'.time().'.'.$extension;
            
            $path = $request->file('proposal')->storeAs('public/application',$fileNameToStore);
       }


            $application = new Application;
    
            $application->proposal =$fileNameToStore;
            $application->user_id = auth()->user()->id;
         
            $application->save();
               
            return redirect('/user/application/view')->with('success', 'Application submitted');
            
    }

0 likes
4 replies
lily90's avatar

i got error in my custom handling error in uploading file.

lily90's avatar

The application proposal failed to upload.

Please or to participate in this conversation.