tsks
This commit is contained in:
Regular → Executable
+74
-9
@@ -3,24 +3,36 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'chatid',
|
||||
'name',
|
||||
'number',
|
||||
'password',
|
||||
'user_name',
|
||||
'is_admin',
|
||||
'plain_id',
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -28,10 +40,7 @@ class User extends Authenticatable
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
protected $hidden = [];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
@@ -40,9 +49,65 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
public function attendances()
|
||||
{
|
||||
|
||||
return $this->hasMany(Attendance::class, 'user_identity', 'user_name')
|
||||
->select('id', 'user_identity', 'entered_at', 'exited_at', 'duration','requested')
|
||||
->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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user