I am getting this error. Method Illuminate\Validation\Validator::validateReqiured does not exist

隐身守侯 提交于 2021-01-29 10:01:13

问题


I am getting this error for validation of form.

Method Illuminate\Validation\Validator::validateReqiured does not exist.

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Event;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationRequired;

class EventController extends Controller
{

protected $events;
public function __construct()
{
    $this->property = new Event();
}
/* get all data */
public function getEvents()
{
    $events =Event::latest()->paginate(5);
    return view ('navbar.viewevents',compact('events'))
    ->with('i',(request()->input('page',1)-1)*5);
}

//view event form
public function viewEventForm()
{
    return view('navbar.events');
}

/* Creating Events */
public function addEvents(Request $request)
{
    $validator = Validator::make($request,[
        'e_name' =>'required',
        'venue' =>'required',
        'e_image' =>'rquired|image|mimes:jpg,jpeg,png',
        'e_status' => 'required'
        ]);
    if ($validator->fails()) {
        return \Redirect::back()
                        ->withErrors($validator)
                        ->withInput();
                            }

    $events = $this->property->addNewEvent($request);
    return \Redirect::back()
            ->with('message','Team member added successfully');
 }

please help to get rid of this error. I had also tried code below.

 $this->validate($request,[
    'e_name' =>'required',
    'venue' =>'required',
    'e_image' =>'rquired|image|mimes:jpg,jpeg,png',
    'e_status' => 'required'
    ]);

I am getting same error for methods. I this code after removing use Illuminate\Validation\ValidationRequired; but same error is appearing. Anyone can help highly be appreciated. Thanks


回答1:


Instead of:

use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationRequired;

Try:

use Validator;

Also, on Laravel 5, you can validate with in the request object (no imports needed):

$request->validate([
    'title' => 'bail|required|unique:posts|max:255',
    'body' => 'required',
]);


来源:https://stackoverflow.com/questions/58762546/i-am-getting-this-error-method-illuminate-validation-validatorvalidatereqiure

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