Zubayer Hossain
Zubayer Hossain

Reputation: 608

how to fix function getClientOriginalExtension() on null on laravel

check out the code that i am getting error on "Call to a member function getClientOriginalExtension() on bool"

i used image intervention properties on laravel to upload image on product table . while usng getClientOriginalExtension() i got error...

public function product_store(Request $request)
{

    $image = $request->hasfile('product_image');
    $img = $image->getClientOriginalExtension();
    $location = public_path('images/products/' .$img);
    Image::make($imge)->save($location);

    $product_image = new productImage;
    $product_image->product_id = 1;
    $product_image->image = $img;
    $product_image->save();

    return redirect() -> route('admin.product.create');
}

Call to a member function getClientOriginalExtension() on bool

Upvotes: 0

Views: 287

Answers (2)

Zubayer Hossain
Zubayer Hossain

Reputation: 608

You can use hasFile() to check if there is a file or not!

if ($request->hasFile('product_image')) {
    $image = $request->file('product_image');
}

then get the extension using :

$imageExt = $image->extension();

Upvotes: 0

Rashed Hasan
Rashed Hasan

Reputation: 3751

hasFile returning boolean.Try this -

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

Upvotes: 5

Related Questions