More fixes for invoice_to, fix PushNew on belongs to relations

This commit is contained in:
Deon George
2020-07-06 16:02:59 +10:00
parent 878277907a
commit b0f9d07af9
5 changed files with 20 additions and 11 deletions

View File

@@ -13,13 +13,18 @@ trait PushNew
{
public function pushNew() {
if (! $this->save()) {
// We dont traverse this models relations
return false;
}
// To sync all of the relationships to the database, we will simply spin through
// the relationships and save each model via this "pushNew" method, which allows
// us to recurse into all of these nested relations for the model instance.
foreach ($this->relations as $models) {
foreach ($this->relations as $key => $models) {
// If we are not pushable, jump to the next item.
if (! is_array($this->pushable) OR ! in_array($key,$this->pushable))
continue;
$models = $models instanceof Collection
? $models->all() : [$models];