Initial V2 commit
This commit is contained in:
14
app/Models/CarLocation.php
Normal file
14
app/Models/CarLocation.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CarLocation extends Model
|
||||
{
|
||||
protected $connection = 'tracking';
|
||||
protected $table = 'car_locations';
|
||||
protected $primaryKey = 'driver_id';
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driver_id', 'latitude', 'longitude', 'heading', 'speed', 'distance', 'status', 'carType'];
|
||||
}
|
||||
12
app/Models/CarRegistration.php
Normal file
12
app/Models/CarRegistration.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CarRegistration extends Model
|
||||
{
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'CarRegistration';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driverID', 'vin', 'car_plate', 'make', 'model', 'year', 'expiration_date', 'color', 'owner', 'color_hex', 'fuel', 'isDefault', 'status', 'vehicle_category_id', 'fuel_type_id'];
|
||||
public const ENCRYPTED_FIELDS = ['car_plate', 'owner'];
|
||||
}
|
||||
105
app/Models/Driver.php
Normal file
105
app/Models/Driver.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Driver Model (Primary DB)
|
||||
*
|
||||
* Note: Primary key is `idn` (auto-increment), but the business ID is `id` (varchar).
|
||||
* All endpoints use `id` (varchar) for lookups, not `idn`.
|
||||
*/
|
||||
class Driver extends Model
|
||||
{
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driver';
|
||||
protected $primaryKey = 'idn';
|
||||
public $timestamps = true;
|
||||
|
||||
const CREATED_AT = 'created_at';
|
||||
const UPDATED_AT = 'updated_at';
|
||||
|
||||
protected $fillable = [
|
||||
'id', 'phone', 'email', 'password', 'gender', 'license_type',
|
||||
'national_number', 'name_arabic', 'issue_date', 'expiry_date',
|
||||
'license_categories', 'address', 'licenseIssueDate', 'status',
|
||||
'birthdate', 'site', 'first_name', 'last_name', 'accountBank',
|
||||
'bankCode', 'employmentType', 'maritalStatus', 'fullNameMaritial',
|
||||
'expirationDate', 'api_key', 'api_secret',
|
||||
];
|
||||
|
||||
protected $hidden = ['password', 'api_secret'];
|
||||
|
||||
/** Encrypted fields that need legacy decryption */
|
||||
public const ENCRYPTED_FIELDS = [
|
||||
'first_name', 'last_name', 'phone', 'gender', 'email',
|
||||
'national_number', 'name_arabic', 'address', 'birthdate',
|
||||
];
|
||||
|
||||
// ── Relationships ──
|
||||
|
||||
public function token()
|
||||
{
|
||||
return $this->hasOne(DriverToken::class, 'captain_id', 'id');
|
||||
}
|
||||
|
||||
public function car()
|
||||
{
|
||||
return $this->hasOne(CarRegistration::class, 'driverID', 'id');
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany(DriverOrder::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
public function ratings()
|
||||
{
|
||||
return $this->hasMany(RatingDriver::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->hasMany(DriverDocument::class, 'driverID', 'id');
|
||||
}
|
||||
|
||||
public function location()
|
||||
{
|
||||
return $this->hasOne(CarLocation::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
public function profileImage()
|
||||
{
|
||||
return $this->hasOne(ImageProfileCaptain::class, 'driverID', 'id');
|
||||
}
|
||||
|
||||
public function healthAssurance()
|
||||
{
|
||||
return $this->hasOne(DriverHealthAssurance::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
public function gift()
|
||||
{
|
||||
return $this->hasOne(DriverGift::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
// ── Scopes ──
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 'notDeleted');
|
||||
}
|
||||
|
||||
public function scopeById($query, string $driverId)
|
||||
{
|
||||
return $query->where('id', $driverId);
|
||||
}
|
||||
|
||||
// ── Helpers ──
|
||||
|
||||
public function getAverageRating(): float
|
||||
{
|
||||
return round($this->ratings()->avg('rating') ?? 5.0, 2);
|
||||
}
|
||||
}
|
||||
10
app/Models/DriverDocument.php
Normal file
10
app/Models/DriverDocument.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DriverDocument extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driver_documents';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driverID', 'doc_type', 'image_name', 'link', 'upload_date'];
|
||||
}
|
||||
10
app/Models/DriverGift.php
Normal file
10
app/Models/DriverGift.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DriverGift extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driver_gifts';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driver_id', 'gift_description', 'gift_date', 'is_claimed'];
|
||||
}
|
||||
10
app/Models/DriverHealthAssurance.php
Normal file
10
app/Models/DriverHealthAssurance.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DriverHealthAssurance extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driver_health_assurance';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driver_id', 'assured', 'date_created', 'health_insurance_provider'];
|
||||
}
|
||||
10
app/Models/DriverOrder.php
Normal file
10
app/Models/DriverOrder.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DriverOrder extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driver_orders';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driver_id', 'order_id', 'notes', 'created_at', 'status'];
|
||||
}
|
||||
12
app/Models/DriverToken.php
Normal file
12
app/Models/DriverToken.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DriverToken extends Model
|
||||
{
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'driverToken';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['token', 'captain_id', 'fingerPrint', 'created_at'];
|
||||
public const ENCRYPTED_FIELDS = ['token'];
|
||||
}
|
||||
10
app/Models/ImageProfileCaptain.php
Normal file
10
app/Models/ImageProfileCaptain.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ImageProfileCaptain extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'imageProfileCaptain';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['driverID', 'image_name', 'upload_date', 'link'];
|
||||
}
|
||||
56
app/Models/Passenger.php
Normal file
56
app/Models/Passenger.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Passenger extends Model
|
||||
{
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'passengers';
|
||||
protected $primaryKey = 'id';
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
public $timestamps = true;
|
||||
|
||||
const CREATED_AT = 'created_at';
|
||||
const UPDATED_AT = 'updated_at';
|
||||
|
||||
protected $fillable = [
|
||||
'id', 'phone', 'email', 'password', 'gender', 'status',
|
||||
'birthdate', 'site', 'first_name', 'last_name', 'sosPhone',
|
||||
'education', 'employmentType', 'maritalStatus',
|
||||
'api_key', 'api_secret',
|
||||
];
|
||||
|
||||
protected $hidden = ['password', 'api_secret'];
|
||||
|
||||
public const ENCRYPTED_FIELDS = [
|
||||
'first_name', 'last_name', 'phone', 'gender', 'email', 'birthdate',
|
||||
];
|
||||
|
||||
public function token()
|
||||
{
|
||||
return $this->hasOne(PassengerToken::class, 'passengerID', 'id');
|
||||
}
|
||||
|
||||
public function wallet()
|
||||
{
|
||||
return $this->hasMany(PassengerWallet::class, 'passenger_id', 'id');
|
||||
}
|
||||
|
||||
public function rides()
|
||||
{
|
||||
return $this->hasMany(Ride::class, 'passenger_id', 'id');
|
||||
}
|
||||
|
||||
public function ratings()
|
||||
{
|
||||
return $this->hasMany(RatingPassenger::class, 'passenger_id', 'id');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 'notDeleted');
|
||||
}
|
||||
}
|
||||
12
app/Models/PassengerToken.php
Normal file
12
app/Models/PassengerToken.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PassengerToken extends Model
|
||||
{
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'tokens';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['token', 'passengerID', 'fingerPrint', 'status'];
|
||||
public const ENCRYPTED_FIELDS = ['token'];
|
||||
}
|
||||
13
app/Models/PassengerWallet.php
Normal file
13
app/Models/PassengerWallet.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PassengerWallet extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'passengerWallet';
|
||||
public $timestamps = true;
|
||||
const CREATED_AT = 'created_at';
|
||||
const UPDATED_AT = 'updated_at';
|
||||
protected $fillable = ['passenger_id', 'balance'];
|
||||
protected $casts = ['balance' => 'decimal:2'];
|
||||
}
|
||||
10
app/Models/RatingDriver.php
Normal file
10
app/Models/RatingDriver.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RatingDriver extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'ratingDriver';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['passenger_id', 'driver_id', 'ride_id', 'rating', 'comment', 'created_at'];
|
||||
}
|
||||
10
app/Models/RatingPassenger.php
Normal file
10
app/Models/RatingPassenger.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RatingPassenger extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'ratingPassenger';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['passenger_id', 'driverID', 'rideId', 'rating', 'comment', 'created_at'];
|
||||
}
|
||||
68
app/Models/Ride.php
Normal file
68
app/Models/Ride.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Ride Model
|
||||
*
|
||||
* Exists on BOTH Primary and Ride databases.
|
||||
* Default connection is 'ride' (for real-time operations).
|
||||
* Use Ride::on('primary') when querying the primary DB copy.
|
||||
*/
|
||||
class Ride extends Model
|
||||
{
|
||||
protected $connection = 'ride';
|
||||
protected $table = 'ride';
|
||||
public $timestamps = false; // Uses custom timestamp columns
|
||||
|
||||
protected $fillable = [
|
||||
'start_location', 'end_location', 'date', 'time', 'endtime',
|
||||
'price', 'passenger_id', 'driver_id', 'status', 'paymentMethod',
|
||||
'carType', 'created_at', 'updated_at', 'DriverIsGoingToPassenger',
|
||||
'rideTimeStart', 'rideTimeFinish', 'price_for_driver',
|
||||
'price_for_passenger', 'distance',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'decimal:2',
|
||||
'price_for_driver' => 'decimal:2',
|
||||
'price_for_passenger' => 'decimal:2',
|
||||
'distance' => 'float',
|
||||
];
|
||||
|
||||
// ── Relationships (cross-database via Primary) ──
|
||||
|
||||
public function driver()
|
||||
{
|
||||
return $this->belongsTo(Driver::class, 'driver_id', 'id');
|
||||
}
|
||||
|
||||
public function passenger()
|
||||
{
|
||||
return $this->belongsTo(Passenger::class, 'passenger_id', 'id');
|
||||
}
|
||||
|
||||
// ── Scopes ──
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->whereIn('status', ['waiting', 'wait', 'Apply', 'Applied', 'Arrived', 'Begin']);
|
||||
}
|
||||
|
||||
public function scopeForPassenger($query, string $passengerId)
|
||||
{
|
||||
return $query->where('passenger_id', $passengerId);
|
||||
}
|
||||
|
||||
public function scopeForDriver($query, string $driverId)
|
||||
{
|
||||
return $query->where('driver_id', $driverId);
|
||||
}
|
||||
|
||||
public function scopeWaiting($query)
|
||||
{
|
||||
return $query->whereIn('status', ['waiting', 'wait']);
|
||||
}
|
||||
}
|
||||
27
app/Models/WaitingRide.php
Normal file
27
app/Models/WaitingRide.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WaitingRide extends Model {
|
||||
protected $connection = 'primary';
|
||||
protected $table = 'waitingRides';
|
||||
protected $primaryKey = 'id';
|
||||
protected $keyType = 'string';
|
||||
public $incrementing = false;
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'id', 'start_location', 'start_lat', 'start_lng', 'end_location',
|
||||
'end_lat', 'end_lng', 'date', 'time', 'price', 'passenger_id',
|
||||
'status', 'carType', 'passengerRate', 'created_at',
|
||||
'price_for_passenger', 'distance', 'duration', 'payment_method',
|
||||
'passenger_wallet',
|
||||
];
|
||||
protected $casts = [
|
||||
'start_lat' => 'decimal:7', 'start_lng' => 'decimal:7',
|
||||
'end_lat' => 'decimal:7', 'end_lng' => 'decimal:7',
|
||||
'price' => 'decimal:2', 'price_for_passenger' => 'decimal:2',
|
||||
];
|
||||
public function scopeWaiting($query) {
|
||||
return $query->where('status', 'waiting');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user