woxene's avatar

Call to a member function store() on null when uploading image

When uploading an image I get the following error: Call to a member function store() on null

Here is my controller code:

public function store(Request $request)
{
    request()->validate([
        'name' => 'required',
        'logo' => 'nullable',
        'original_filename' => 'nullable',
    ]);
    
    if ($request->hasFile('logo')) {
        $path = $request->file('file')->store('fileupload');
        $fileinfo = $request->file('file');
        
        $request->merge([
            'logo'              => $path,
            'original_filename' => $fileinfo->getClientOriginalName(),
        ]);
    }
    
    Carrier::create($request->all());
    return redirect()->route('carriers.index')->with('toast', 'Carrier created successfully.');
}

I want the script to upload the file to the folder /fileupload and add logo and original_filename to the database.

0 likes
1 reply
woxene's avatar
woxene
OP
Best Answer
Level 1

Got it working, I forgot the change ('file') to ('logo').

3 likes

Please or to participate in this conversation.