fCompayUser != null) { return $this->fCompayUser; } $this->fCompayUser = User::findOrFail(2); return $this->fCompayUser; } public function firstCompany(){ return 1; } public function secondCompany(){ return 2; } private $sCompayUser; public function secondCompanyUser() { if ($this->sCompayUser != null) { return $this->sCompayUser; } $this->sCompayUser = User::findOrFail(4); return $this->sCompayUser; } /** * Save or update database records * * @param $table * @param $attributes */ public function saveOrUpdate($table, $attributes) { foreach ($attributes as $attr) { $record = null; if(isset($attr['id'])) { $record = \DB::table($table)->find($attr['id']); } if ($record != null) { $attr['updated_at'] = Carbon::now(); if ($record->created_at == null) { $attr['created_at'] = Carbon::now(); } $insertedOrUpdated = \DB::table($table)->updateOrInsert(['id' => $attr['id']], $attr); } else { $attr['created_at'] = Carbon::now(); $inserted = \DB::table($table)->insert( $attr); } } } }