php - Laravel Update if record exists or Create if not -
i want update record if exists create new 1 if not exists. here got far: merchantbranch.php public function token() { return $this->hasone('app\merchantbranchtoken'); } merchantbranchtoken.php public function merchant_branch() { return $this->belongsto('app\merchantbranch'); } $find = merchantbranchtoken::find($id); if (!$find) { $branch = new merchantbranchtoken(['token' => $token]); merchantbranch::find($id)->token()->save($branch); } else { $find->token = $token; $find->save(); } it's working perfectly. but know laravel powerful eloquent model. can make shorter? or doing correctly?. i've tried using "updateorcreate" method foreign key "merchant_branch_id" need fillable. laravel using methodology save function $user->save() laravel code // if model exists in database can update our record // in database using current ids in ...