我在验证表单时遇到此错误。
方法Illuminate \ Validation \ Validator :: validateReqiured没有 存在。
<?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');
}
请帮助摆脱该错误。我也在下面尝试过代码。
$this->validate($request,[
'e_name' =>'required',
'venue' =>'required',
'e_image' =>'rquired|image|mimes:jpg,jpeg,png',
'e_status' => 'required'
]);
我在方法上遇到了同样的错误。我将这段代码删除后使用Illuminate \ Validation \ ValidationRequired;但出现相同的错误。任何人都可以提供帮助,不胜感激。谢谢
答案 0 :(得分:0)
代替:
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationRequired;
尝试:
use Validator;
此外,在Laravel 5上,您可以在request对象中进行验证(无需导入):
$request->validate([
'title' => 'bail|required|unique:posts|max:255',
'body' => 'required',
]);