validateReqiured不存在

validateReqiured不存在

本文介绍了我收到此错误.方法Illuminate \ Validation \ Validator :: validateReqiured不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在验证表单时遇到此错误.

I am getting this error for validation of form.

<?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'
    ]);

我在方法上遇到了同样的错误.我将这段代码删除后使用Illuminate \ Validation \ ValidationRequired;但出现相同的错误.任何人都可以提供帮助,不胜感激.谢谢

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

推荐答案

而不是:

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

尝试:

use Validator;

此外,在Laravel 5上,您可以在request对象中进行验证(无需导入):

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',
]);

这篇关于我收到此错误.方法Illuminate \ Validation \ Validator :: validateReqiured不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:36