Answer the question
In order to leave comments, you need to log in
Linking models with link type morphTo?
There are two models...
class BalanceOperation extends \Model
{
protected $table = 'gc_balance_operations';
public function contractor()
{
return $this->morphTo();
}
...
}
class Client extends \Model
{
protected $table = 'gc_clients';
public function balanceOperations()
{
return $this->morphMany(BalanceOperation::class, 'contractor');
}
...
}
$operation->contractor_type = get_class($contractor);
$operation->contractor_id = $contractor->id;
$operation->save();
Answer the question
In order to leave comments, you need to log in
Должно работать так, при условии, что связь правильно настроена.
$operation->contractor()->associate($contractor);
$operation->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question