M
M
Morfeey2019-03-11 14:46:45
Laravel
Morfeey, 2019-03-11 14:46:45

Synchronization/updating related laravel models, how to do it normally?

There are 2 related models, how to synchronize correctly?

class Site extends Model 
{
    public function phrase()
    {
        return $this->hasOne(Phrase::class, 'site_id', 'id');
    }
}

Unsuccessful synchronization attempt:
$phrases = [];
        foreach ($request->get('phrases') as $phrase) {
            $phrases[] = (new Phrase());
        }
        $site->phrase()->sync($phrases);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question