Skip to content

Instantly share code, notes, and snippets.

@arosemena
Created August 23, 2018 15:22
Show Gist options
  • Save arosemena/502fb67ab2db1255031b05156821cab1 to your computer and use it in GitHub Desktop.
Save arosemena/502fb67ab2db1255031b05156821cab1 to your computer and use it in GitHub Desktop.
HTTP Middleware for Laravel
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TransformsRequest;
class FixDates extends TransformsRequest
{
protected function transform($key, $value)
{
// Transform the ISO 8601 from quasar components to a plain date
$match = "/^(-?(?:[1-9]\d*)?\d{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12]\d)T(2[0-3]|[01]\d):([0-5]\d):([0-5]\d)(.\d+)?\-?(\d{2}):?(\d{2})/";
return preg_match($match, $value) ? substr($value, 0, 10) : $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment