The ->with(...) after the view(...) is how er pass variables from the controller to view.
return view('appointedStudents')->with('students', $students);
This method allows you to use a different name for that variable in your view. So if you kept as before you would have to change your view to:
@if (count($appointedStudents)>0) @foreach ($appointedStudents as $student) ...
As before the last change you were renaming the $students variable in the controller to $appointedStudents in the view through the ->with(...) method.
What do you want to destroy? Every appointment with a student? or a student record?
Unfortunately, right now I don't have the time, my suggestion is you to open a new issue in the "Assistance" category.
But basically the outline will be the following:
1. Add a delete route mapped to dedicated controller method
// routes/web.php
Route::delete('/appointments/student/{student}', 'AppointmentsController@destroy');
2. Add the destroy controller method to the AppointmentsController
public function destroy(Student $student) {
$user = Auth::user();
Appointment::query()
->where('counselor_id', $user->id) // filter by current user
->where('student_id', $student->id)
->delete();
return back();
}
If your Student model is named like that Laravel will automatically fetch the related instance by its primary key
3. in your blade for each interaction add a form with a remove button:
<li class="list-group-item">Name: {{$student->name}}</li>
<li class="list-group-item">Email: {{$student->email}}</li>
<li class="list-group-item">Counselor Type: {{$student->matric}}</li>
<li class="list-group-item">
<form method="POST" action="/appointments/student/{{ $student->id }}"
class="d-inline-block"
onsubmit="return confirm('Are you sure?')">
@csrf @method('DELETE')
<button type="submit" class="btn btn-danger">
remove
</button>
</form>
</li>
</li>