Created
August 8, 2022 22:22
-
-
Save jeffersongoncalves/a28b1c334b142c14bb66facae781b938 to your computer and use it in GitHub Desktop.
Bind url date format Ymd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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