/**
  * @param Request $request
  * @param string $id
  * @return RedirectResponse|\Illuminate\View\View
  */
 public function newOrEditAction(Request $request, $id = '')
 {
     $viewModel = [];
     $customer = $id ? $this->customerRepository->getById($id) : new Customer();
     if ($request->getMethod() == 'POST') {
         $this->inputFilter->setData($request->request->all());
         if ($this->inputFilter->isValid()) {
             $this->hydrator->hydrate($this->inputFilter->getValues(), $customer);
             $this->customerRepository->begin()->persist($customer)->commit();
             Session::flash('success', 'Customer Saved');
             return new RedirectResponse('/customers/edit/' . $customer->getId());
         } else {
             $this->hydrator->hydrate($request->request->all(), $customer);
             $viewModel['error'] = $this->inputFilter->getMessages();
         }
     }
     $viewModel['customer'] = $customer;
     return view('customers/new-or-edit', $viewModel);
 }
 public function newOrEditAction()
 {
     $id = $this->params()->fromRoute('id');
     $viewModel = new ViewModel();
     $customer = $id ? $this->customerRepository->getById($id) : new Customer();
     if ($this->getRequest()->isPost()) {
         $this->inputFilter->setData($this->params()->fromPost());
         if ($this->inputFilter->isValid()) {
             $customer = $this->hydrator->hydrate($this->inputFilter->getValues(), $customer);
             $this->customerRepository->begin()->persist($customer)->commit();
             $this->flashMessenger()->addSuccessMessage('Customer saved.');
             $this->redirect()->toUrl('/customers/edit/' . $customer->getId());
         } else {
             $this->hydrator->hydrate($this->params()->fromPost(), $customer);
             $viewModel->setVariable('errors', $this->inputFilter->getMessages());
         }
     }
     $viewModel->setVariable('customer', $customer);
     return $viewModel;
 }