0
votes

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
Typo: rquired should be required - brombeer
After correct spellings i am getting same error. - Robert Williams
Have you tried removing the line use Illuminate\Validation\ValidationRequired;? Where does that line come from? No such file exists - brombeer
Yes tried this thing as well but same error appears. - Robert Williams

1 Answers

0
votes

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