<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\DB;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'fullname', 'username', 'email', 'password', 'role_id', 'active',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function isSupervisor ()
{
return $this->role_id === 1;
}
public function isAgent ()
{
return $this->role_id === 2;
}
public function isFirm ()
{
return $this->role_id === 3;
}
public function group()
{
return $this->BelongsTo('App\Group');
}
public function role()
{
return $this->BelongsTo('App\Role');
}
public function appointment()
{
return $this->hasMany('App\Appointment', 'agent_id');
}
public function unqualifiedAppointments()
{
return $this->appointment->where('status_id', 1)->count();
}
public function receivedAppointments()
{
return $this->appointment->where('status_id', 2)->count();
}
public function confirmedAppointments()
{
return $this->appointment->where('status_id', 3)->count();
}
public function validAppointments()
{
return $this->appointment->where('status_id', 4)->count();
}
public function canceledAppointments()
{
return $this->appointment->where('status_id', 5)->count();
}
public function recallAppointments()
{
return $this->appointment->where('status_id', 6)->count();
}
}
for example how can I remodel unqualifiedAppointments function to get this month's records only?
ok so you write a query that returns all records where month =08. . this is fine this year, but then in 2021, you query all records where the month is 08 and now you get twice the number you expected because you get all from 08/20 and all from 08/21