Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vipin93's avatar
Level 13

How to retrive $students who not submit fee in current month?

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'));
   }
0 likes
4 replies
vipin93's avatar
Level 13

@HeXiaodong but here is the if what if a students who submitted last month but not in current month

hxd's avatar
hxd
Best Answer
Level 2

$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.