/** * IMPORTANT: Call this function name on the Controller to verify this action is allowed * Implement putToteIntoPallet($toteID, $palletID) */ public function putToteIntoPallet($toteID, $palletID) { $tote = GenericContainer::findOrFail($toteID); $pallet = Pallet::findOrFail($palletID); $container = DB::connection(Pallet::CONNECTION_NAME)->table('container')->where('objectID', $toteID)->first(); Log::info("Put Tote {$toteID} into Pallet {$palletID}"); if (isset($container)) { $result = DB::connection(Pallet::CONNECTION_NAME)->table('container')->where('containerID', $container->containerID)->update(['parentID' => $palletID, 'objectID' => $toteID]); // $result === 1/true if the container was updated // $result === 0/false if no containers were updated if ($result === 1 or $result === 0) { return true; } } else { $result = Container::create(['parentID' => $palletID, 'objectID' => $toteID]); // $result == container object created if (isset($result) and get_class($result) == 'App\\vital3\\Container') { return true; } } Log::error('putToteIntoPallet failed'); //dd(__METHOD__.'('.__LINE__.')',compact('toteID','palletID','tote','pallet','container','result')); return ['putToteIntoPallet failed']; }