How can I show the number of students per course in an index view?
These are the relationships in my models Student:
public function curso()
{
return $this->belongsTo(Curso::class,'id_curso','id');
}
Course:
public function alumnos()
{
return $this->hasMany('App\Alumno','id_curso');
}
Someone who helps me please I am new to this, my idea is a count of students where the course id is equal to the course in question, but for that I need the ID of the course. this is my controller
public function index(Request $request)
{
$cursos = Curso::search($request->nombre)->orderBy('nombre','ASC')->paginate(10);
return view('cursos.index')->with('cursos',$cursos)->with('i', ($request->input('page', 1) - 1) * 5);
}