Krishna_Shrestha's avatar

Call to a member function getClientOriginalName() on string

says FatalThrowableError Call to a member function getClientOriginalName() on string while uploading image

        $image = request('image');
        $filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
        Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products/'.$filename);
        $product->image = 'img/products/'.$filename;
        $product->save();

form code

{{ Form::open(array('route'=>['products.create','files'=>true, 'method' => 'get'])) }}

0 likes
2 replies
rumm.an's avatar

use this instead

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

make sure you set enctype attribute in your form to 'multipart/form-data' like this

<form enctype="multipart/form-data" method="POST">
3 likes
AddWebContribution's avatar

As per laravel documentation, change code like below:

$image = $request->file('image');
$filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products/'.$filename);
$product->image = 'img/products/'.$filename;
$product->save();

Please or to participate in this conversation.