FounderStartup's avatar

Call to a member function getClientOriginalExtension() on null error

Getting this error while updating home page image. Very strangely similar code is working fine for upload of site logo ?

    public function HomeImageUpdate(Request $request){

        $old_image = $request->old_image;
        If ($old_image <> NULL) unlink("images/logos/".$old_image);

        $image = $request->file('homeopageimage');
        $name_gen = hexdec(uniqid()).'.'.$image->getClientOriginalExtension();
        Image::make($image)->save('images/logos/'.$name_gen);

            Logo::findOrFail(1)->update([
                'homepageimage' => $name_gen,
            ]);

        $notification = array(
            'message' => 'Site Image Updated Successfully',
            'alert-type' => 'success'
        );

        return redirect()->back()->with($notification);

    } // end method

0 likes
9 replies
Snapey's avatar
Snapey
Best Answer
Level 122

the form probably does not have a field called homopageimage

$image = $request->file('homeopageimage');

where is your validation?

1 like
FounderStartup's avatar

@Snapey oops !! it was a typo :) Its homepage not homeopageimage :) And I tried so many tricks to find the bug :) Anyway thanks for your time . Keep shining.

axeloz's avatar

@FounderStartup I must agree with @snapey. Where is the validation? You should have a:

public function HomeImageUpdate(Request $request){
	$request->validate([
		'homepage'		=> 'required|image|max:1000'
	]);

Something like this

1 like
Snapey's avatar

@axeloz otherwise a php file could be uploaded in place of the image

2 likes
FounderStartup's avatar

@Snapey Just one query ! Why should we validate in the controller also when we are already having validations in the blade ?

Please or to participate in this conversation.