S
S
semki0962019-04-22 09:22:57
Laravel
semki096, 2019-04-22 09:22:57

Why is the field not editable if it is empty?

There are 2 tables, products and descriptions. Connected in a one-to-one relationship. I'm trying to edit the product description from descriptions

$product->description->body = $request->getParam('body');
$product->description->save();

Works if $product->description->bodythere is already a description in it. If absent, it returns Creating default object from empty value in ...And $request->getParam('body');not empty. Where did I go wrong? I would be grateful for help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andrei_pro, 2019-04-22
@semki096

$product->description()->save(new Description(['body' => $request->body]));
или
$product->description()->update(['body' => $request->body]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question