Answer the question
In order to leave comments, you need to log in
How to change the values of one column while adding another?
There is a questions table that contains questions from users. Default status = No response. So, when the admin adds the answer to the question (the body column), the status itself should change to published.
Laravel just recently started learning, thanks to everyone for the advice.
Sample table prntscr.com/jmhhe1
Answer the question
In order to leave comments, you need to log in
Create an observer
class UserObserver
{
/**
* Прослушивание события обновление вопроса
*
* @param Question $question
* @return void
*/
public function updating(Question $question)
{
if ($question->body != $question->getOriginal('body ')) {
$question->status = 'опубликован';
}
}
}
For the model, add an answer() method that will call update() or save()
public function answer(string $body)
{
return $this->update(['body' => $body, 'status' => 'Опубликован']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question