Files
Kent-logistics-Laravel/app/Models/User.php
Utkarsh Khedkar 9cc6959396 Pdf Changes Done
2026-03-09 10:24:44 +05:30

114 lines
2.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'customer_id',
'customer_name',
'company_name',
'designation',
'email',
'mobile_no',
'address',
'pincode',
'date',
'password',
// newly added customer fields
'status', // active / inactive
'customer_type', // premium / regular
'profile_image', // optional image
];
/**
* Attributes that should be hidden.
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Attribute casting.
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
/**
* 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
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* JWT Custom Claims
*/
public function getJWTCustomClaims()
{
return [];
}
public function invoices()
{
return $this->hasMany(\App\Models\Invoice::class, 'customer_id', 'customer_id');
}
// App\Models\User.php
public function invoiceInstallments()
{
return $this->hasManyThrough(
InvoiceInstallment::class,
Invoice::class,
'customer_id', // FK on invoices
'invoice_id' // FK on installments
);
}
}