xxxxxxxxxx
Nthe difference depends on where your foreign key is.
In your example, if A has a b_id column, then A belongsTo B.
If B has an a_id column, then A hasOne or hasMany B depending on how many B should have.
xxxxxxxxxx
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Phone extends Model
{
/**
* Get the user that owns the phone.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
//User
public function clinicAgent()
{
return $this->hasOne(AgentReferral::class , 'clinic_id','id');
}
//AgentReferral
public function clinic(){
return $this->belongsTo(User::class,'clinic_id','id');
}
//has many
//user
public function doctorSchedule()
{
return $this->hasMany('App\Models\ClinicTimetable','doctor_id','id');
}
//doctor
public function doctorName()
{
return $this->belongsTo(User::class,'doctor_id','id');
}