Question

I've just updated L4 (both skeleton and packages) to the latest version.

Now, when I try to create a new instance of one of the Models and save it to the DB, I get an empty record, except for the timestamps and the primary key.

This behaviour persists over all models (Users, Bids, Projects etc...) so It's not a local problem.

I tried both

Project::create($project);

and, following this thread:

$new_project = new Project;

$new_project->fill($project);

$new_project->save();

But the result is the same: an empty record.

Was it helpful?

Solution

So, as it turns out from the docs Mass assignment is now blocked by default for security reasons (e.g fetching all data from the form without specifying the fields (Input::all()) and saving it as is to the DB might result in unwanted fields being assigned, in case the client manipulates the form by adding a field with a name that corresponds to the field in the DB).

To designate the fields that are allowed to be assigned, one should either explicitly add the fields in question as a white-list to a protected $fillable array on the model, or alternatively, create a black-list using the $guarded array

OTHER TIPS

i was facing the same problem and found solution hope help others

$new_project = new Project;

$new_project->unguard();

$new_project->create($project);

$new_project->reguard();


or

Project::unguard();
$new_project = Project::create($project);
$new_project->reguard();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top