BossPogs
4 months ago
1027
9
Laravel

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

Posted 4 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">
</form>

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;
            $student->save();

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

            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.