O
O
ObehanProger2019-04-06 09:35:26
Laravel
ObehanProger, 2019-04-06 09:35:26

How to update a record in a table if some cells of the data array may be empty?

On the profile settings page, the user can fill in / change several, or maybe just one field. In this case, the $request array may contain empty cells. And the command
$user->update($request-all());
will not work or reset the values ​​in some columns. It is clear that you can iterate through the array and throw out empty values, but then you will have to specify all the fields to be filled in the update method.
Is there a toolkit in eloquent that will do everything itself so as not to fence a lot of code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-04-06
@jazzus

An empty field is not passed to the request

<input name="name" value="{{$user->name}}" required="">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question