I'm using $casts to save data in array to database. I have an issue with that.
How can i push data to an existing array in the database?
For example i have already an array of data in my db column like:
$brand = Brand::find($request->input('brand'));
$brand->model = $request->input('model');
You cannot do this with Eloquent's Mass Assignment functions (update, create, etc). You must pull down your field, change it, then save the model.
$collection = collect($brand->field); $collection->push($myNewData); $brand->field = $collection->toJson(); $brand->save();