https://laravel.com/docs/5.3/eloquent-relationships#querying-relationship-absence
maybe you can use whereDoesntHave function to retrive students.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using subscription type app, here is the problem. like I have table"subscriptions" where admin collect the fee and submit with students ID, but here is that. I want to retrive students who not submit fee in current month. my subscription table
Schema::create('subscriptions', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id')->unsigned()->index();
$table->integer('course_id')->unsigned()->index();
$table->string('other_fee')->default('0');
$table->string('tution_fee');
$table->string('late_fee')->default('0');
$table->string('transportation_fee')->default('0');
$table->string('remarks')->default('Fees submited of this month');
$table->timestamps();
});
Subscription Model
public function students()
{
return $this->belongsTo(Student::Class,'student_id');
}
Student Model
public function subscriptions()
{
return $this->hasMany(Subscription::Class)->latest();
}
controller
public function unpaid()
{
$dt = Carbon::now();
$sub = Student::whereHas('subscriptions', function ($query) use($dt) {
$query->whereMonth('created_at','!=',$dt->month); })->paginate(15);
return view('search.search_unpaid',compact('sub'));
}
$sub = Student::whereDoesntHave('subscriptions', function ($query) use($dt) {
$query->whereMonth('created_at','=',$dt->month); })->paginate(15);
did it helps?
Please or to participate in this conversation.