user11124425
user11124425

Reputation: 971

BadMethodCallException explication?

When, I want to create a recording I have this error message?

enter image description here

BadMethodCallException in => C:\wamp64\www\exemple\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php line 74: Method validate does not exist.

I don't understand the problem?

Controller - Student

public function index()
    {
        $students = Student::oldest()->paginate(5);
        return view('admin.students.index', compact('students'))
          ->with('i', (request()->input('page',1) -1)*5);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.students.create', compact('students'));
    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request)
    {
        $request->validate([
                'name' => 'required',
                'firstname' => 'required'

        ]);


       $exists = Student::where('name', $request->get('name'))->where('firstname', $request->get('firstname'))->count();

       if (!$exists){
            Student::create($request->all());
            return redirect()->route('students.index')
                ->with('success', 'new data created successfully');
        }

        else{
            return redirect()->route('students.index')
                ->with('error', 'doublon');

        }   

    }

Upvotes: 0

Views: 1377

Answers (1)

Abdulla
Abdulla

Reputation: 515

Try the following code. Replace request by this

$this->validate([
      'name' => 'required',
      'firstname' => 'required'
]);

Upvotes: 1

Related Questions