aleksov's avatar

Upload photo: Call to a member function getClientOriginalExtension() on a non-object

I have this function to store Article:

public function store(Requests\ArticleRequest $request) { $article = new Article($request->all()); $article['key']= str_random(30);

    $imageName = $article['key'] . '.' . 
    $request->file('image')->getClientOriginalExtension();

    $request->file('image')->move(
    base_path() . '/public/images/catalog/', $imageName
    );
    

    Auth::user()->articles()->save($article);

    Alert::success('SUPER!','Good job!')->persistent("Close");



    return redirect('auctions');
}

offcource at blade view file I have:

{!! Form::label('Product Image') !!} {!! Form::file('image', null) !!}

Now when I try to submit article everything is fine except image becouse I get error:

Call to a member function getClientOriginalExtension() on a non-object

How to solve this problem?

0 likes
6 replies
cklmercer's avatar

Double check and make sure that your form has enctype="multipart/form-data"

aleksov's avatar

Also dd($request->file('image')); give me :null

cklmercer's avatar

@aleksov After you get your form setup properly (see the post above by @thomaskim) you'll be free to move the file anywhere you like using the move method.

// Move file to /public/images
$request->file('image')->move(public_path('/images'));

Please or to participate in this conversation.