In addition to the assignment method in the model, you can also check by defining a new method:
class Assignment extends Model { public function assignments() { return $this->hasMany(<YOUR_ASSIGNMENTS_TABLE_NAME>::class, 'id_assignment', 'id_id'); } // new method public function checkStudentAssignmentIsNull() { return $this->hasMany(<YOUR_ASSIGNMENTS_TABLE_NAME>::class, 'id_assignment', 'id_id') ->where('<YOUR_ASSIGNMENTS_TABLE_NAME>.id_student', Auth::user()->id) ->first() === null; } }
When using, you can use !$data->checkStudentAssignmentIsNull()
instead of !empty($data->assignments->id_student)
.
I can see your table more clearly now:
// new method public function checkStudentAssignmentIsNull() { return $this->hasMany(AssignmentDetail::class, 'id_assignment', 'id_id') ->where('assignment_details.id_student', Auth::user()->id) ->first() === null; }