Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotsofbytes/829266703c7404e93e522d75643a7d4e to your computer and use it in GitHub Desktop.
Save lotsofbytes/829266703c7404e93e522d75643a7d4e to your computer and use it in GitHub Desktop.
[バリデーション:date] #laravel #L55 #validation

バリデーション:date

日付の文字列かを判定。

laravel 5.5

gistの画面

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

$ git clone git@gist.github.com:829266703c7404e93e522d75643a7d4e.git tests/Unit/Validations/Date
<?php
namespace Tests\Unit\Validations\Date;
use Tests\TestCase;
use Validator;
class DateTest extends TestCase
{
/**
* @test
* @dataProvider provider_date
*/
public function date($input, $expected)
{
$v = Validator::make(
$input,
['field' => 'required|date']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_date()
{
return [
[['field' => '10/09/18'], true], // MM/DD/YY
[['field' => '2018-09-10'], true],
[['field' => '10 September 2018'], true],
[['field' => 'September 2018'], true],
[['field' => 'now'], false],
[['field' => '+1 day'], false],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment