0

I am new to Laravel. While adding the update option dynamically into my site, the BLOB image is not being updated. Here is my function :

public function update_giftcard($id , Request $data){
    $gift['name'] = $data->name;
    $gift['description'] = $data->description;

    $gift['category'] = $data->category;


    /*IMG STORAGE*/
    if($data->hasFile('img')) {
        $image = $data->file('img')->getClientOriginalName();
        $data->file('img')->move("uploads", $image);
        $gift['image'] = $image;
    }

    Giftcards::where('id' , $id)->first()->update($gift);
}

Here when I do echo $gift['image'], the filename is printed successfully and the image is being uploaded successfully too but it is not being updated in the mysql database.

Hope I get an answer, thanks.

1
  • I do not see where you save the image file into a blob. I can see you saving the name of the image only. Commented Aug 26, 2020 at 7:38

1 Answer 1

2

You're updating the data using the mass assignment. Did you add 'image' in $fillable?

Go to your model Giftcards and add

protected $fillable = [
    'image'
];
Sign up to request clarification or add additional context in comments.

1 Comment

I did do the mass assignment but upon rechecking there was a typo in the $fillable causing the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.