Hello im getting the following error while upload an image using laravel: "Call to a member function getClientOriginalExtension() on null".
Here is my controller:
$imageName = rand(11111, 99999) . '.' . $request->file('image')->getClientOriginalExtension();
$destinationPath = 'events';
$fileName = rand(11111, 99999) . '.' . $extension;
$upload_success = $image->move($destinationPath, $imageName);
Here is my view:
{!! Form::file('image', null, ['class' => 'form-control']) !!}
How do i save the $imageName to the pic field in my database. I tried this but it doesn't work. The field remains empty in the table.
$task=$request->user()->tasks()->create([
'name' => $request->name,
'description' => $request->description,
'location' => $request->location,
'pic' => $imageName,
]);
in your form:open
you need the 'files' => true
like below
Form::open('your_path', array('files' => true))
or
<form action="your_path" method="post" enctype="multipart/form-data">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With