You can use Regular Expression Constraints to only accept correct data.
Multiple optional route parameters to make up date
In short, I'm building a dashboard where by default it shows an overview for the current day. If a specific date is supplied then the details are shown for that date. This is the approach I've thought of so far.
Route::get('dashboard/{year?}/{month?}/{day?}', ... );
tl;dr
- Is the approach above ok?
- How do I deal with invalid dates?
None / Invalid
/dashboard
If no date elements are provided, or they are invalid, then the current day is shown.
Year
/dashboard/2015
If only a year is supplied then the overview displays results for that year, or the current year to date (Jan 1st - Present).
Year and Month
/dashboard/2016/03
If a year and month are supplied then the overview is shown for the whole month, or if it is the current month then it will show details for the 1st of the month until the present day.
Year, Month, and Day
/dashboard/2016/05/17
If all three are provided then the details are shown for that specific date.
Please or to participate in this conversation.