lawkunchi's avatar

Multiple file upload

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();
    }
0 likes
3 replies
Sergiu17's avatar

So what's the problem? Can't save an array ( paths ) into docs column?

Sergiu17's avatar

@LAWKUNCHI - That's true, you need to implode this array into a string, or whatever you chose.

'docs' = implode(', ' $paths);

You may store as JSON, or create a separate table for files

Please or to participate in this conversation.