Files
intaleq_v2/app/Models/Ride.php
2026-04-22 21:59:56 +03:00

69 lines
1.8 KiB
PHP

<?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']);
}
}