Files
Kent-logistics-Laravel/app/Models/User.php

100 lines
2.1 KiB
PHP
Raw Normal View History

2025-11-04 10:19:07 +05:30
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
2025-11-05 15:44:04 +05:30
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
2025-11-04 10:19:07 +05:30
2025-11-05 15:44:04 +05:30
class User extends Authenticatable implements JWTSubject
2025-11-04 10:19:07 +05:30
{
use HasFactory, Notifiable;
2025-11-07 12:08:34 +05:30
/**
* The attributes that are mass assignable.
*/
2025-11-04 10:19:07 +05:30
protected $fillable = [
2025-11-18 10:01:59 +05:30
'customer_id',
2025-11-07 12:08:34 +05:30
'customer_name',
'company_name',
'designation',
2025-11-04 10:19:07 +05:30
'email',
2025-11-07 12:08:34 +05:30
'mobile_no',
'address',
'pincode',
'date',
2025-11-04 10:19:07 +05:30
'password',
2025-11-18 10:01:59 +05:30
// newly added customer fields
'status', // active / inactive
'customer_type', // premium / regular
'profile_image', // optional image
2025-11-04 10:19:07 +05:30
];
2025-11-07 12:08:34 +05:30
/**
2025-11-18 10:01:59 +05:30
* Attributes that should be hidden.
2025-11-07 12:08:34 +05:30
*/
2025-11-04 10:19:07 +05:30
protected $hidden = [
'password',
'remember_token',
];
2025-11-07 12:08:34 +05:30
/**
2025-11-18 10:01:59 +05:30
* Attribute casting.
2025-11-07 12:08:34 +05:30
*/
2025-11-04 10:19:07 +05:30
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
2025-11-05 15:44:04 +05:30
2025-11-07 12:08:34 +05:30
/**
2025-11-18 10:01:59 +05:30
* Relationship: User MarkList (Many)
*/
public function marks()
{
return $this->hasMany(\App\Models\MarkList::class, 'customer_id', 'customer_id');
}
/**
* Relationship: User Orders (Through MarkList)
*/
public function orders()
{
return $this->hasManyThrough(
\App\Models\Order::class,
\App\Models\MarkList::class,
'customer_id', // MarkList.customer_id
'mark_no', // Orders.mark_no
'customer_id', // Users.customer_id
'mark_no' // MarkList.mark_no
);
}
/**
* JWT Identifier
2025-11-07 12:08:34 +05:30
*/
2025-11-05 15:44:04 +05:30
public function getJWTIdentifier()
{
return $this->getKey();
}
2025-11-07 12:08:34 +05:30
/**
2025-11-18 10:01:59 +05:30
* JWT Custom Claims
2025-11-07 12:08:34 +05:30
*/
2025-11-05 15:44:04 +05:30
public function getJWTCustomClaims()
{
return [];
}
2025-12-01 11:44:43 +05:30
public function invoices()
{
return $this->hasMany(\App\Models\Invoice::class, 'customer_id', 'id');
}
2025-11-04 10:19:07 +05:30
}