Hi, use Try Catch and Database Transactions
handle unknown null values from request
Hi, I am inserting a large table and I would like to know how I can circumvent the queryException, where if query has null in value (and column is not null), it would insert a default value.
I am not interested in changing the table's nullability.
there are many table columns and I don't wan't to end up doing $table->'default' on 56 columns.
I am using mass assignment with create($request->all(), question is, where in that request I can create a rule of thumb where I would be able to insert string/integer instead of null.
I ended up pacifying null attributes via an array in model and then merged in a create request for model, as follows:
$newWally = WallyConfig::create(array_merge($request->all(),
WallyConfig::NON_WALLY_PACIFIED_COLUMNS));
return $newWally;
NON_WALLY_PACIFIED_COLUMNS is the array that holds key/value which handles an immense number of request values (returning null), since this re-occurs it was the most relevant solution that I saw. I reckon Mutators is a fancier way of doing what I did.
Thanks for the help gentlemen.
Please or to participate in this conversation.