oliverbj
oliverbj

Reputation: 6052

PHP / Laravel - Advanced relationship and dynamic amount of columns

I am trying to recreate below logic in Laravel:

enter image description here

Now this is a dynamic sailing schedule, currently created in Excel. In my Laravel app, I would like to for each origin/destination (Origin to Destination):

I am having a hard time grasping the logic required to do this.

Right now, my thoughts were to:

  1. Create a Carriers model and table, which holds all the different carriers (for example "ACL")
  2. Create a Vessels model and table, which holds all the different vessels, for a specific carrier (For example "Atlantic Sky" and "Atlantic Sail"). I will then define a hasOne relationship on these two models.

Now I will also need some sort of table, that holds the specific route (For example New York to Copenhagen and then list all carriers that have this route.

However, I am not able to grasp how I should do this when I need to be able to dynamically add as many ETD and ETA points?

My thought was to:

  1. Create a Routes model, which then holds the routing information such as (vessel_id, cut_off_date) - but how do I go about creating the `etd1, etd2, etd3, eta1, eta2, eta3 columns when this can vary from route to route?

Upvotes: 0

Views: 109

Answers (2)

Elisha Senoo
Elisha Senoo

Reputation: 3594

I recommend you pass the data as JSON data in the body of a POST request.

Otherwise, pass them as a url-encoded json object in the url parameters.

Something like this:

$myDataObj = [["type" => "ETD", "city" = "New York", "date" = "6/NOV"]
              ["type" => "ETA", "city" = "Boston", "date" = "12/NOV"]];

$myDataJSON = json_encode($myDataObj);

Then you can add $myDataJSON as a parameter value in your json-encoded url.

Upvotes: 0

Cody Caughlan
Cody Caughlan

Reputation: 32748

Sounds like your Route model would have a vessel-id and the start and end destinations. Then a routes_stops model or something like that would detail all of the individual stops between the start & end.

Upvotes: 1

Related Questions