I'd suggest following Eloquent conventions for your database design. It makes things easier if you do it how Eloquent expects it.
https://laravel.com/docs/5.6/eloquent#eloquent-model-conventions
So, you'd have 3 tables, with (at least) the following fields
classes (plural)
-id
students (plural)
-id
class_student (singular name of each table, in alphabetical order)
-class_id (singular table name, followed by underscore id (_id)
-student_id (singular table name, followed by underscore id (_id)
Laravel expects that the pivot table be a combination of the 2 tables it's using, using the singular name of each table, and in alphabetical order. These can of course be overridden, but it makes it more complicated, especially if you're just starting out.
Then you'd have 2 models: Class and Student. Both would have a many-to-many relationship. https://laravel.com/docs/5.6/eloquent-relationships#many-to-many
So in the Student model
public function classes() {
return $this->belongsToMany(App\Class::class);
}
and the Class model would be the opposite
public function students() {
return $this->belongsToMany(App\Student::class);
}
Then, to find the students who are in a class with id of 4.
$class = Class::with('students')->find(4);
@foreach ($class->students as $student)
{{ $student->name }}
@endforeach
To find the classes that a student with id of 10 has
$student = Student::with('classes')->find(10);
@foreach ($student->classes as $class)
{{ $class->title }}
@endforeach