Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

grahamd's avatar

I have my classes! Best approach to inputs!

TLDR; I've probably answered my own question, but seek re-assurance on direction, please read :P

So I have set myself a simple task of modelling an event calendar.

  • There's one calendar showing one day at a time
  • Per date there's a number of 'events' depicting available 'bookings'

So I have my Event, representing start and end times, EventCollection representing a collection of these Events, and a Calendar representing a single collection of events, along with any applicable calendar related information.

The calendar, regardless of input will build up a collection of events marked as available, then, depending on if the current date is today, then it'll mark a number of these available blocks as unavailable since I want to build in lead time for preparation for these events to occur.

Once I have selected a number of dates from the UI representing the calendar, I'm storing these to a session for processing after the next UI, which will confirm the selected events.

These are passed using the key of an input, for example 1030_1130, 1200_1300.

So far, all of the above is completely fine, I've got this working with some test data, but now comes the inclusion of persistence and inputs.

Given that the form handler will return an array of times for the events 'selected', what is the best strategy of putting these inputs back into my event collection (not the calendar this time since we'll be using a booking class), taking into account that the reverse of this operation, retrieving from the database for editing, will present the data in a different way.

I've toyed around with populateFromDb, populateFromInput, but I feel the need to gouge my eyes out since I know there's something missing!

Eloquent converts all dates to Carbon, so I feel I need to present the data to the class using a common interface, so all I'd need to do is convert my form inputs into carbons and pass them using the applicable 'addEvent' and Bob's your Grannies Uncle!

Would this be a scenario for building an interface, and if I want to pass form inputs, that I'd just reference the interface and use whichever type the source data came from?

Would this be in say, the form of 'formEventRepository'? What's the best strategy to name this?

I'm all too hung up on the strategy of all of this, but I'm trying to build common classes, and handle it in such a way I can throw data at it in many forms, and have the big old classes doing the leg work for me!

Advice is more than welcome!

0 likes
3 replies
grahamd's avatar

If you got as far as reading this reply, thanks for reading :)

nolros's avatar

Long read, you had me at classes :) Is the issue taking an array from one input and mapping to another table / table or pushing it back out to another form? Also, are you attempting to map data or columns?

grahamd's avatar

So I guess to put it simply

Source data supplied to calendar class which in turn builds a collection of events which will allow me to do the processing on.

Two distinct data sources :

form input [start_end => 1030_1130] -> calendar class -> events collection -> events

database [start => carbon date, end => carbon date] -> calendar class -> events collection -> events

if input is instance of carbon, do this -> populateFromDB if input is not, do this -> populateFromInput

Update

Since I originally wrote this forum message, I've used the request class to format my inputs into carbon dates so that they're consistent with carbon from the database, which is a dependency of the calendar class.

(I'm using L5, so this made it simple to just extend the request).

Now, whether I'm editing this from source data from the input, or the database, the calendar class does not care!

Please or to participate in this conversation.