Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 19:45
Show Gist options
  • Save lotsofbytes/cf9b3e9d622790c7d749e449bd3d851b to your computer and use it in GitHub Desktop.
Save lotsofbytes/cf9b3e9d622790c7d749e449bd3d851b to your computer and use it in GitHub Desktop.
[バリデーション:date_format] #laravel #L55 #validation

バリデーション:date_format

指定のパターンの日付の文字列かを判定。

laravel 5.5

gistの画面

以下の実行で、ダウンロードできます

$ git clone git@gist.github.com:cf9b3e9d622790c7d749e449bd3d851b.git tests/Unit/Validations/DateFormat
<?php
namespace Tests\Unit\Validations\DateFormat;
use Tests\TestCase;
use Validator;
class DateFormatTest extends TestCase
{
/**
* @test
* @dataProvider provider_date_format
*/
public function date_format($input, $expected)
{
$v = Validator::make(
$input,
['field' => 'required|date|date_format:Y-m-d']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_date_format()
{
return [
[['field' => '2018-01-01'], true],
[['field' => '1/1/18'], false],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment