Download the PHP package darkghosthunter/laradate without Composer
On this page you can find all versions of the php package darkghosthunter/laradate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download darkghosthunter/laradate
More information about darkghosthunter/laradate
Files in darkghosthunter/laradate
Package laradate
Short Description Route bind a date into a Carbon (or anything you want)
License MIT
Homepage https://github.com/darkghosthunter/laralerts
Informations about the package laradate
Laradate
Parse a date from the URL, receive it as a Carbon
instance in your controller.
Requirements
- Laravel 8.x or later
- PHP 8.0 or later.
For older versions support, consider helping by sponsoring or donating.
Installation
You can install the package via composer:
Usage
Simply set the date
parameter to any route. In your controller, you will get a Carbon
instance if the name of the variable is $date
.
A date must be formatted as
YYYY-MM-DD
to reach the route, otherwise it won't be found.
Behind the scenes, Laradate will use the DateFactory
, which is the default factory in your application, to create instances of DateTimeInterface
. By default, your application uses the Carbon library.
If the datetime cannot be parsed, the route will return HTTP 404.
Using formats
You can also use custom formatting for your routes with {date:format}
. The format follows the same Datetime formats. If the string doesn't follow the format, the route will return an HTTP 404.
Because of limitations of Laravel Router parameters for bindings, use underscore
_
as separator while using formats.
Date between middleware
To avoid having to fallback to the Laravel Validator inside the controller, you can use the date
middleware which accepts a minimum, maximum, or both, dates to compare (inclusive). If the date is not inside the dates, an HTTP 404 code will be returned.
Since the dates are passed to DateTime
, you can use words like today 00:00
or 3 months 23:59:59
for relative dates.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of laradate with dependencies
ext-json Version *
illuminate/support Version ^8.0
illuminate/routing Version ^8.0
illuminate/http Version ^8.0
nesbot/carbon Version >=2.51.1