I have three tables: 1. patients 2. finances tables, 3. vital
what i want is to send patients to vital page after they paid in finance table if they have payment request to pay, otherwise, i want send them to vital if their status is active and payment value ==0
my finance model:
class Finance extends Model
{
use HasFactory;
protected $table='finances';
protected $fillable = ['service_cost','service_name','recevied_by','pmrn'];
public function patien():HasOne
{
return $this->hasOne(Patient::class,'id', 'mrn');
}
}
my patient model:
class Patient extends Model
{
use HasFactory;
protected $table='patients';
// public $timestamps = false;
protected $fillable = ['mrn','f_name','m_name','l_name','sex','age','region','zone','woreda','kebele','village','house_no','phone','marital_status','email','status','cardpayamount','lastpaiddate'];
}
vital model:
class Vital extends Model
{
use HasFactory;
protected $table='vitals';
// public $timestamps = false;
protected $fillable = ['chief_complain','history_allergy','blood_pressure','pressure_rate','spo2','rr', 'pid','temperature','past_medical_illness','illnes_time','transfer_to','triaged_by'];
}
i want something like this in my vital index function page:
$lastpaid = Finance::get();
$pat = Patient::get();
if ($lastpaid->pmrn == $pat->id && $lastpaid->updated_at == $pat->updated){
$patients = DB::table('patients')->where('status', '1')->paginate(10);
}
else{
$patients = DB::table('patients')->where('status', '1')->where('cardpayamount', '0.0000', Carbon::today())->latest()->paginate(10);
}
return view('vital.index', compact('patients'));
but i have error message
Exception
Property [pmrn] does not exist on this collection instance.