jet

Class App\Http\Requests\ScholarshipRequest does not exist

Posted 3 months ago by jet

need help don't know what am doing wrong

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\ScholarshipRequest;
use App\Scholarship; 
use Auth;
use Session;

class ScholarshipController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         $scholarships = Scholarship::all();
        return view('scholarship.index', ['scholarships' => $scholarships]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
         $scholarship = new Scholarship();
        return view('scholarship.form', ['scholarship' => $scholarship, 'action' => 'create', 'countries' => $scholarship->getCountries()]);
    }

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

        if(Scholarship::create($data)) {
            
            Session::flash('success', 'sucessfully save!');
            return redirect('/scholarships');
        } else {
            return 'there was an error';
        }

      
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $scholarship = Scholarship::findOrFail($id);
        return view('scholarship.form', ['scholarship' => $scholarship, 'action' => 'edit', 'countries' => $scholarship->getCountries()]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(ScholarshipRequest $request, $id)
    {
        $validated = $request->validated();
        $data = $request->input();
        unset($data['_token']);
        unset($data['_method']);
        $data['user_id'] = Auth::user()->id;

        if(Scholarship::where('id', $id)->update($data)) {
            $data = $request->all();
            Session::flash('success', 'Scholarship sucessfully updated!');
            return redirect('/scholarships');
        } else {
            return 'there was an error';
        }

        $data->save();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
         if (Scholarship::findOrFail($id)->delete()) {
            return response()->json('');
            Session::flash('success', 'The scholarship was sucessfully deleted.');
        } 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.