Multiple file upload

Posted 6 months ago by lawkunchi

How do I store file paths of multiple file upload input. Below is my controller so far

public function postDeal(Request $request) 
    {
        $this->validate($request, [

            'property_address' => 'string|required|max:100',
            'sell_price' => 'string|required|max:100',
            'docs' => 'required|max:10000',
        ]);

        $files  = $request->file('docs');
        $paths = [];

        foreach( $files as $file) {
            $extension = $file->getClientOriginalExtension();
            $filename = 'sup-doc-' . time() . '.' . $extension;
            $paths[] = $file->storeAs('Deals', $filename);
        }

        $deal = new Deal([
            'property_address' => $request->input('property_address'),
            'sell_price' => $request->input('sell_price'),
            'docs' => $paths,
        ]);
        $deal->save();
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.