orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
138 stars 34 forks source link

Saving a record does not respect the $fillable of the model #20

Closed rabol closed 3 years ago

rabol commented 3 years ago

the saving of a resource uses forceFill() meaning that it will add fields to a model that is not in the db e.g. when using a matrix.

tabuna commented 3 years ago

Hi, we use the forceful method by default to be as open as possible to newbies who do not fill in the model properties. But you can easily control these things: https://github.com/orchidsoftware/crud#resource-events

For example, you can put:

/**
 * Action to create and update the model
 *
 * @param ResourceRequest $request
 * @param Model           $model
 */
public function onSave(ResourceRequest $request, Model $model)
{
    $model->fill($request->all())->save();
}
rabol commented 3 years ago

But using forceFill() with e.g. a Matrix() will give you SQL errors

tabuna commented 3 years ago

Why can you give an example? You put the matrix field to the model property that uses cast in JSON, for example