Method validate does not exist - Laravel 5.4

久未见 提交于 2019-12-03 23:23:06
arku

In docs said:

$this->validate($request, [
    'email' => 'required|email',
]);

This string - works :)

AddWeb Solution Pvt Ltd

You should try this:

$validateFields = array('email' => 'required|email');

$this->validate($request, $validateFields);

OR

$this->validate($request, [
    'email' => 'required|email'
]);

Well means its no longer available in 5.4 however its available in controller

Try:

 $this->validate($request, [
    'email' => 'required|email',
 ]);

Actually If you add the right controller, validate method should be already included. You can try adding below controller.

Instead: use App\Http\Controllers\Controller;

        $validator = \Validator::make($request->all(), [
            'mobile_number' => 'required',]);

        if ($validator->fails()) {
            return redirect()->back()
            ->withErrors($validator)
            ->withInput();
        }

Hope this works for you..

You can use the Validator service provider.

     namespace App\Http\Controllers;

     use Newsletter;
     use Illuminate\Http\Request;
     use Validator;

     class SubscriptionController extends Controller
     {
          public function subscribe(Request $request)
          {
                   $request->validate($request->all(),[
                     'email' => 'required|email',
                  ]);
           }

lets add these two packages Best of luck

use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!