alaayush's avatar

move() function doesn't work while updating images.

I have a founder page where the user can upload name, information and image of the founder. In my view when I edit pictures and upload a new one, the name of the pictures gets stored in the database but the image is not being uploaded. There must be some problem in my controller but i can't seem to find out what. Any help would be appreciated.

Below are my model and controller.

class Founder extends Model { protected $fillable = ['name','information', 'image'];

 public function getImageAttribute()
 {
     if (! $this->attributes['image']) {
       return 'noimage.jpg';
 }

 return $this->attributes['image'];

} public function getCreatedAtAttribute($date) { return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d'); }

public function getUpdatedAtAttribute($date) { return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d'); }

Controller:

public function update(Request $request, $id) {

$founder = Founder::find($id);
$input  = $request->all();

if($file=$request->file('image'))
{
    $name = $file->getClientOriginalName();
    $file->move('/images/', $name);
    $input['image']= $name;
}
$founder->update($request->all());
return redirect()->route('founder.view');

}

0 likes
1 reply

Please or to participate in this conversation.