Files
a.montask/app/Models/User.php
T

117 lines
3.0 KiB
PHP
Raw Normal View History

2025-07-10 18:23:56 +00:00
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
2025-10-11 13:38:30 +00:00
use Carbon\Carbon;
2025-07-10 18:23:56 +00:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
2025-10-11 13:38:30 +00:00
use Illuminate\Support\Facades\DB;
use Morilog\Jalali\Jalalian;
2025-07-10 18:23:56 +00:00
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
2025-10-11 13:38:30 +00:00
2025-07-10 18:23:56 +00:00
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'email',
2025-10-11 13:38:30 +00:00
'chatid',
'name',
'number',
2025-07-10 18:23:56 +00:00
'password',
2025-10-11 13:38:30 +00:00
'user_name',
'is_admin',
'plain_id',
2026-04-08 07:22:13 +00:00
'break',
'req_counts',
2025-10-11 13:38:30 +00:00
2025-07-10 18:23:56 +00:00
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
2025-10-11 13:38:30 +00:00
protected $hidden = [];
2025-07-10 18:23:56 +00:00
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
2025-10-11 13:38:30 +00:00
return [];
2025-07-10 18:23:56 +00:00
}
2025-10-11 13:38:30 +00:00
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)
2026-04-08 07:22:13 +00:00
)->withPivot(['id', 'started_at','ended_at','duration',]);
2025-10-11 13:38:30 +00:00
}
public function attendances()
{
return $this->hasMany(Attendance::class, 'user_identity', 'user_name')
2026-04-08 07:22:13 +00:00
->select('id', 'user_identity', 'entered_at', 'exited_at', 'duration','requested', 'distance', 'distance_exit')
2025-10-11 13:38:30 +00:00
->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
2026-04-18 06:17:01 +00:00
)->orderBy('id', 'desc');
2026-04-08 07:22:13 +00:00
2025-10-11 13:38:30 +00:00
}
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;
}
2025-07-10 18:23:56 +00:00
}