/**
  * Implement destroy($id)
  */
 public function destroy($id)
 {
     $location = $this->locationRepository->find($id);
     $deleted = false;
     if (isset($location)) {
         /*
          * In the case of a Location delete request
          * 1. make sure there are no Pallets in this Location
          * ok to delete
          */
         $pallets = $this->palletRepository->filterOn(['container.parent' => $id]);
         Log::debug('Pallets: ' . (isset($pallets) ? count($pallets) : 'none'));
         if (isset($pallets) and count($pallets) > 0) {
             $children = Lang::get('labels.titles.Pallets');
             $model = Lang::get('labels.titles.Location');
             $errors = [[Lang::get('internal.errors.deleteHasChildren', ['Model' => $model, 'Children' => $children])]];
             return Redirect::back()->withErrors($errors)->withInput();
         }
         //dd(__METHOD__.'('.__LINE__.')',compact('id','location','pallets'));
         $this->transaction(function ($this) use($id, &$deleted) {
             $deleted = $this->locationRepository->delete($id);
         });
     }
     Log::debug('deleted: ' . ($deleted ? 'yes' : 'no'));
     return Redirect::route('location.index');
 }
Esempio n. 2
0
 /**
  * Locate this resource
  */
 public function locate($pltID, $id)
 {
     // if guest or cannot pallet.edit, redirect -> home
     if (Entrust::can('pallet.edit') == false) {
         return redirect()->route('home');
     }
     // using an implementation of the Pallet Repository Interface
     $pallet = $this->palletRepository->find($pltID);
     $inLocation = $this->locationRepository->find($id);
     //dd(__METHOD__.'('.__LINE__.')',compact('pltID','id','pallet','inLocation'));
     // update container set parentID = $id where objectID = $pltID;
     $result = $this->locationController->putPalletIntoLocation($pltID, $id);
     if ($result !== true) {
         return Redirect::back()->withErrors($result)->withInput();
     }
     return redirect()->route('pallet.show', ['id' => $pltID]);
 }