Validate method not found - Laravel -


laravel framework 5.4.35

contacts controller:

<?php  namespace app\http\controllers;  use illuminate\http\request;  use illuminate\routing\redirector;  use illuminate\support\facades\mail;  use app\mail\contactemail;  class contactscontroller extends controller {     public function index() {         return view('contact.index');     }      public function sendcontact (request $request) {          $request->validate([             'name' => 'required|min:3',             'email' => 'required|email',             'message' => 'required|min:5',         ]);          mail::to('bump@bumpy.net')                 ->send(new contactemail($request));          return redirect('/contact/success');     }      public function success() {         return view('contact.success');     } } 

the controller extends:

<?php  namespace app\http\controllers;  use illuminate\foundation\bus\dispatchesjobs; use illuminate\routing\controller basecontroller; use illuminate\foundation\validation\validatesrequests; use illuminate\foundation\auth\access\authorizesrequests;  class controller extends basecontroller {     use authorizesrequests, dispatchesjobs, validatesrequests; } 

when goes here:

$request->validate([                 'name' => 'required|min:3',                 'email' => 'required|email',                 'message' => 'required|min:5',             ]); 

i output:

(1/1) badmethodcallexception method validate not exist

i have namespace, classes used. call method seems ok.

what missing?

care advise?

if create validator instance manually using validator facade. seems validate.

you mention using version 5.4. method you're using validats via request version 5.5.

so need like...

$this->validate($request, [     'name' => 'required|min:3',             'email' => 'required|email',             'message' => 'required|min:5', ]); 

hope helps. check out 5.4v docs rather the, aster/5.5v https://laravel.com/docs/5.4/validation#validation-quickstart

laravel 5.4

$this->validate($request, [ 

laravel 5.5

$request->validate([ 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -