lundi 30 septembre 2019

How to insert/assign evenly to all my vehicles the packages that are to be delivered?

I am new here please forgive me in case of formatting errors. I have a problem that's been troubling me these past few days. It involves assigning packages evenly among my delivery trucks. What my code does right now is it checks the counter for a column on my delivery_trucks table. If it reaches 10 total packages, it now moves on to the next delivery truck. Basically the first few trucks are loaded with packages while the other trucks have none to deliver. It delivers daily so it resets daily as well. How do i evenly assign packages to all my trucks? Here's my current code:

public function deliverPackages(Request $request)
{
      $package = $this->package;

      $packageid = $request['packageid'];
      $packagename = $request['packagename'];
      $qty = $request['qty'];
      $delivery_truck = DeliveryTruck::status()->package()->first(); -- This code right here is what i want to change
      $package->receiver__id = $request['receiver_id'];
      $package->deliverytruck_id = $delivery_truck->deliverytruck_id;
      $package->total = $request['total'];

      --and a few more unrelated code
}  

Status() checks if the truck is in working condition. A bit more information, how do i implement it if for example all my trucks from #1 to #10 each have 1 package. When all have been assigned a package each, it now returns to truck #1 and it repeats until all packages are assigned evenly to my trucks.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2n5Dprq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire