Skip to content

Instantly share code, notes, and snippets.

@jeffersongoncalves
Created August 8, 2022 22:22
Show Gist options
  • Save jeffersongoncalves/a28b1c334b142c14bb66facae781b938 to your computer and use it in GitHub Desktop.
Save jeffersongoncalves/a28b1c334b142c14bb66facae781b938 to your computer and use it in GitHub Desktop.
Bind url date format Ymd
<?php
namespace App\Providers;
use Carbon\Carbon;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class RouteServiceProvider extends ServiceProvider
{
public function boot()
{
$this->bind('dateof', function ($dateof) {
$carbon_date = Carbon::createFromFormat('Ymd', $dateof);
if ($carbon_date->format('Ymd') === $dateof) {
return $carbon_date;
}
throw new NotFoundHttpException();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment