php - $casts, array data -
i'm using $casts save data in array database. have issue that.
how can push data existing array in database? example have array of data in db column like: ["some_data", "another_el"]
, on , in controller want push in array in db other data input.
$brand = brand::find($request->input('brand')); $brand->model = $request->input('model'); $brand->update();
pushing data this.
you cannot eloquent's mass assignment functions (update, create, etc). must pull down field, change it, save model.
$collection = collect($brand->field); $collection->push($mynewdata); $brand->field = $collection->tojson(); $brand->save();
Comments
Post a Comment