Laravel hasMany relationship detach all

Yes, you can detach all the college students as below. Actually, we already have the college_id in your students table and we have to make this college_id null somehow. This is not called detach in Eloquent. The word detach come when you have many to many relationships. So, let's just update the students and see if it works or not.

$college->students()->update(['college_id' => null);

So, you method can be completed as below:

public function detachAllStudents()
{
    $college->students()->update(['college_id' => null]);
}

That's it!