Skip to content

Instantly share code, notes, and snippets.

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

バリデーション:before

入力値が指定の日付より過去かを判定。

laravel 5.5

gistの画面

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

$ git clone git@gist.github.com:590983f0bdd25a7e0c4ba1ee99b1d300.git tests/Unit/Validations/Before
<?php
namespace Tests\Unit\Validations\Before;
use Tests\TestCase;
use Validator;
class BeforeTest extends TestCase
{
/**
* @test
* @dataProvider provider_before
*/
public function before($input, $expected)
{
$v = Validator::make(
$input,
['field' => 'required|date|before:2018-01-01']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_before()
{
return [
[['field' => '2017-12-31'], true],
[['field' => '12/31/17'], true],
[['field' => '2018-01-02'], false],
[['field' => '2018-01-01'], false],
[['field' => '1/2/18'], false],
[['field' => '1/1/18'], false],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment