Reputation: 39
I have controller with the action
public function postContact(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required | email',
'content' => 'required'
]);
if(empty($this->validate->fails())){
die('wrong');
return redirect()->route('contact')->withInput();
}
return ('right');
}
When I don't fill in all input this dies on the wrong statement, but when I fill in all the input this error occurs:
ErrorException in PageController.php line 123: Undefined property:
App\Http\Controllers\PageController::$validate
How can I fix this? Thank for reading my answer: Image
Upvotes: 1
Views: 4757
Reputation: 163788
It should be:
if (empty($this->validate()->fails())) {
Because validate()
is a method, not property.
https://laravel.com/docs/5.4/validation#quick-writing-the-validation-logic
Upvotes: 1