问题
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