App\Ninja\Repositories\TaxRateRepository::save PHP Méthode

save() public méthode

public save ( $data, $taxRate = null )
    public function save($data, $taxRate = null)
    {
        if ($taxRate) {
            // do nothing
        } elseif (isset($data['public_id'])) {
            $taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
            \Log::warning('Entity not set in tax rate repo save');
        } else {
            $taxRate = TaxRate::createNew();
        }
        $taxRate->fill($data);
        $taxRate->save();
        return $taxRate;
    }

Usage Example

 /**
  * @param UpdateTaxRateRequest $request
  * @param $publicId
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateTaxRateRequest $request, $publicId)
 {
     if ($request->action) {
         return $this->handleAction($request);
     }
     $data = $request->input();
     $data['public_id'] = $publicId;
     $taxRate = $this->taxRateRepo->save($data, $request->entity());
     return $this->itemResponse($taxRate);
 }