Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 67524e8

Browse files
Merge pull request janhenkgerritsen#9 from llstarscreamll/custom-validation
Added exists rule validation to post input, show errors on view, and adjust tests
2 parents 1307b21 + 2fe05fe commit 67524e8

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

‎app/Http/Controllers/HomeController.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public function fireEvent()
102102
public function validation(Request $request)
103103
{
104104
$this->validate($request, [
105-
'postal_code' => 'required|postal_code'
105+
'post_id' => 'required|exists:posts,id',
106+
'postal_code' => 'required'
106107
]);
107108

108109
return 'Validation success';

‎resources/views/hello.blade.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
@section('main')
44
<h1>Hello world!</h1>
5+
6+
@if (count($errors) > 0)
7+
<div class="alert alert-danger">
8+
<ul>
9+
@foreach ($errors->all() as $error)
10+
<li>{{ $error }}</li>
11+
@endforeach
12+
</ul>
13+
</div>
14+
15+
{{var_dump(\App\Post::all()->toArray())}}
16+
17+
@endif
18+
519
@stop

‎tests/functional/CustomValidationCest.php‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22

33
class CustomValidationCest
44
{
5+
public function _before(FunctionalTester $I)
6+
{
7+
$I->haveRecord('posts', [
8+
'title' => 'Hello Universe',
9+
'body' => 'You are so awesome',
10+
'created_at' => new DateTime(),
11+
'updated_at' => new DateTime()
12+
]);
13+
}
14+
515
public function testCustomValidationSuccess(FunctionalTester $I)
616
{
7-
$I->amOnPage('validation?postal_code=1234AB');
17+
$I->amOnPage('validation?postal_code=1234AB&post_id=1');
818
$I->see('Validation success');
919
}
1020

1121
public function testCustomValidationError(FunctionalTester $I)
1222
{
13-
$I->amOnPage('validation?postal_code=1234');
23+
$I->amOnPage('validation?postal_code=&post_id=123456');
1424
$I->seeFormErrorMessage('postal_code');
25+
$I->seeFormErrorMessage('post_id');
1526
}
16-
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /