Files
intaleq_v2/app/Models/Ride.php
2026-04-24 00:18:27 +03:00

75 lines
2.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* نموذج الرحلة (Ride Model)
*
* الغرض من الملف:
* تمثيل بيانات "الرحلة" في قاعدة البيانات. هذا الملف هو المسؤول عن التعامل مع جدول (ride).
*
* كيفية العمل:
* 1. يربط الكود بجدول الرحلات ويحدد الحقول التي يمكن كتابتها (fillable).
* 2. يحدد قاعدة البيانات المستخدمة؛ حيث أن الرحلات موجودة في قاعدة بيانات منفصلة (ride connection) لسرعة الأداء.
* 3. يحتوي على علاقات (Relationships) مع السائق والراكب.
* 4. يحتوي على "Scopes" وهي اختصارات لعمليات البحث المتكررة (مثل البحث عن الرحلات النشطة فقط).
*/
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'])
->where('created_at', '>=', now()->subHours(1));
}
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']);
}
}