jet
578
4
Laravel

Method Illuminate\Validation\Validator::validateReqiured does not exist.

Posted 6 months ago by jet

pls help

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\AdmissionRequest;
use App\models\University;
use App\models\Admission;
use Auth; 
use Session;



class AdmissionController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $admissions = Admission::all();

        return view('admission.index', ['admissions' => $admissions]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $admission = new Admission();
        return view('admission.form', ['admission' => $admission, 'action' => 'create', 'universities' => University::all()]);
    }


    /**
     *
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(AdmissionRequest $request)
    {
        $validated = $request->validated();
        $data = $request->input();
        unset($data['_token']);
        $data['user_id'] = Auth::id();
        $data['slug'] = $data['program'] .'-'. $data['level']. '-20180'. $data['university_id'];

        if(Admission::create($data)) {

             Session::flash('success', 'sucessfully save!');
            return redirect('/admissions');
        } else {
            return 'there was an error';
        }

    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $admission = Admission::findOrFail($id);
        return view('admission.show', ['admission' => $admission]);

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $admission = Admission::findOrFail($id);
        return view('admission.form', ['admission' => $admission, 'action' => 'edit', 'universities' => University::all()]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function update(AdmissionRequest $request, $id)
    {

        $validated = $request->validated();
        $data = $request->input();
        unset($data['_token']);
        unset($data['_method']);
        $data['user_id'] = Auth::user()->id;
        $data['slug'] = str_replace(' ', '-', strtolower($data['program'])) .'-'. str_replace(' ', '-', strtolower($data['level'])). '-20180'. $data['university_id'];

        if(Admission::where('id', $id)->update($data)) {

            Session::flash('success', 'sucessfully save!');
            return redirect('/admissions');
        } else {
            return 'there was an error';
        }

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
        if (Admission::findOrFail($id)->delete()) {
            return response()->json('');
        } else {
            return 'there was an error';
        }
    }

}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.