5 months ago

Missing required parameters for [Route: student.destroy] [URI: student/{student}]

Posted 5 months ago by BossPogs

Hello. I had confused with that error above and I double check that code I include the parameter. Check my code below

<form action="{{ route('student.destroy', $student->id) }}" method="POST" onsubmit="return confirm('Are you sure you want to unenroll?');" style="display: inline-block;">
                     <input type="hidden" name="_token" value="{{ csrf_token() }}">
                     <input type="hidden" name="_method" value="DELETE">
                     <input type="submit" class="btn btn-danger" value="Unenroll">

My code in controller

public function destroy($id)
        $student = Student::where('student_id', $id)->first();

        //reset to active
        if ($student->enrolled == 0){
            $student->enrolled = 1;

            return redirect()->back()->with('success','Student was successfully enrolled');
            $student->enrolled = 0;

            return redirect()->back()->with('error','Student is now unenrolled');

I'm still wondering why I get the error missing required parameters even I had already that one.

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