Support the ongoing development of Laravel.io →
Requests Input

hello every one

i have a Category model and its have only name and image field

so for making a new category its work fine

but when its come to update

i have a small issue

i make the code work like this :-

1 - if the user upload a file then it will take the file and put the path on the field 2 - if not then it will grab the previous value of the image field and put it in the field

the problem with the first step

its upload the file but its return an empty value in the image field and dosnt update it !!

this is my code

http://laravel.io/bin/eDDkn#17-18

i try to use

$request->merge([ 'image' => public_path().'/images/categories/'.$image;, ]);

but same thing

it always give me this response

{ "id": 1, "name": "Small Car2", "created_at": "2015-05-21 12:51:11", "updated_at": "2015-05-22 08:14:11", "image": {} }

as the image : {}

and btw even when the field not updated the file was upload and move successfully

Last updated 2 years ago.
0

Do you add $fillable variable in your category model?

http://laravel.com/docs/5.0/eloquent#mass-assignment

Last updated 9 years ago.
0

barisbora said:

Do you add $fillable variable in your category model?

http://laravel.com/docs/5.0/eloquent#mass-assignment

i think u didnt read my issue

i dont have issue with mass assignment as it work in the second condition

and also it work when i need to store a new category

0

no need i just find a way

$category->update([ 'name'=> $request->get('name'), 'image' => $request->get('image') ]);

will solve it

i dono why

$category->update($request->all());

have an issue >_<

0

Sign in to participate in this thread!

Eventy

Your banner here too?

8lbiasian 8lbiasian Joined 6 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.