D
D
Dmitry Sudarkin2019-03-02 00:44:46
Laravel
Dmitry Sudarkin, 2019-03-02 00:44:46

Why save() doesn't save certain options?

Hey!
Restriction or not - I do not understand. I didn’t find an answer in the documentation ... I
save it like this, despite the fact that the fields in the table are (id, param1, param2)

$app= new App;
$app->param1= 1;
$app->param2= 2;
$app->save();

Added param3 in the table, and the above query no longer saves.
It is necessary to add the newly made param3 parameter to the request like this
$app= new App;
$app->param1= 1;
$app->param2= 2;
$app->param3= '';
$app->save();

Keeping track of all requests is not easy... How to save exactly those parameters that are required at the moment? How to get rid of the mandatory prescribing of a parameter in a request?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
guerrrka, 2019-03-02
@GrozInventor

As far as I understand the question, you need to set the default value for param3 to Null

R
Roman, 2019-03-02
@procode

Everything is fine with me when the parameters are only partially set
Turn on the debug in .env - it will tell you what exactly is wrong
And it looks like Guerrka is right - set the default value in the database itself - null

R
Reeboot, 2019-03-04
@reeboot

It is best to use this method:
In the model, add:

protected $fillable =[
'field1',
'field-n' //fields to be filled in
];

and save like this:
$item = (new BlogCategory())->create($request->all());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question