Пример #1
0
 /**
  * Register any other events for your application.
  *
  * @param  \Illuminate\Contracts\Events\Dispatcher  $events
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     GenericContainer::creating(function ($genericContainer) {
         return $genericContainer->isCreating();
     });
     GenericContainer::saving(function ($genericContainer) {
         return $genericContainer->isSaving();
     });
     InboundOrder::creating(function ($inboundOrder) {
         return $inboundOrder->isCreating();
     });
     InboundOrderDetail::creating(function ($inboundOrderDetail) {
         return $inboundOrderDetail->isCreating();
     });
     Inventory::creating(function ($inventory) {
         return $inventory->isCreating();
     });
     Inventory::saving(function ($inventory) {
         return $inventory->isSaving();
     });
     Item::creating(function ($item) {
         return $item->isCreating();
     });
     JobExperience::creating(function ($jobExperience) {
         return $jobExperience->isCreating();
     });
     JobStatus::creating(function ($jobStatus) {
         return $jobStatus->isCreating();
     });
     Location::creating(function ($location) {
         return $location->isCreating();
     });
     Location::saving(function ($location) {
         return $location->isSaving();
     });
     Pallet::creating(function ($pallet) {
         return $pallet->isCreating();
     });
     Pallet::saving(function ($pallet) {
         return $pallet->isSaving();
     });
     PerformanceTally::creating(function ($performanceTally) {
         return $performanceTally->isCreating();
     });
     User::creating(function ($user) {
         return $user->isCreating();
     });
 }
 /**
  * Implement create($input)
  */
 public function create($input)
 {
     return InboundOrderDetail::create($input);
 }
 /**
  * Implement update($id, $input)
  */
 public function update($id, $input)
 {
     $pod = InboundOrderDetail::find($id);
     $updatedPod = $pod->update($input);
     //TODO find a way to automate which $name's are Additional, should not be hardcoded here.
     //TODO Found it!, if we subtract original attribute names from attributes, we get this list of Additional names
     $name = 'Location';
     //$newValue = $input[$name];
     if (isset($input[$name])) {
         $additional = InboundOrderDetailAdditional::where('objectID', $id)->where('Name', $name)->first();
         if (isset($additional)) {
             $additional->update(['Value' => $input[$name]]);
             $additional->save();
             //dd(compact('id','input','newValue','additional'));
             // Update does not appear to be working, deleting the record instead
             InboundOrderDetailAdditional::where('objectID', $id)->where('Name', $name)->delete();
         }
         if ($input[$name] > 0) {
             InboundOrderDetailAdditional::create(['objectID' => $id, 'Name' => $name, 'Value' => $input[$name]]);
         }
     }
     return $updatedPod;
 }