Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Call to a member function getClientOriginalExtension() on null

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,
        ]);
like image 324
velvt Avatar asked May 09 '16 20:05

velvt


1 Answers

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">
like image 170
Camilo Rojas Avatar answered Nov 03 '22 15:11

Camilo Rojas