*/ use HasFactory, Notifiable, softDeletes; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'email', 'chatid', 'name', 'number', 'password', 'user_name', 'is_admin', 'plain_id', 'break', 'req_counts', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = []; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return []; } public function task() { return $this->hasMany(Tasks::class, 'user_id'); } // public function tasks() // { //// return $this->belongsToMany(Tasks::class, 'pivot_tasks', 'user_id', 'task_id'); // return $this->belongsToMany( // Tasks::class, // مدل مقصد // 'pivot_tasks', // جدول واسط // 'user_id', // ستون جدول واسط که به جدول users اشاره می‌کنه // 'task_id', // ستون جدول واسط که به جدول tasks اشاره می‌کنه // 'plain_id', // ستون جدول users که ستون جدول واسط بهش اشاره می‌کنه (local key) // 'task_id' // ستون جدول tasks که ستون جدول واسط بهش اشاره می‌کنه (related key) // )->withPivot(['id', 'started_at','ended_at','duration',]); // } public function attendances() { return $this->hasMany(Attendance::class, 'user_identity', 'user_name') ->select('id', 'user_identity', 'entered_at', 'exited_at', 'duration','requested', 'distance', 'distance_exit') ->orderBy('entered_at', 'desc'); } public function attendanceBreaks() { return $this->hasManyThrough(AttendanceBreak::class,Attendance::class,'user_identity','attendance_id', 'user_name', // local key در users 'id' // local key در attendances )->orderBy('id', 'desc'); } // public function thismonth($data) // { // // } public function everymonth($data) { $result = []; foreach ($data->attendances as $att) { if ($att->entered_at) { $date = \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($att->entered_at)); $month = $date->format('%B'); if (!isset($result[$month])) { $result[$month] = []; } $result[$month][] = $att; } } return $result; } }