There is a Client
Model and a Lead
model:
class Client extends Model
{
protected $fillable = [
'fn',
'ln'
];
public function fullName()
{
return new Attribute(
get: fn () => $this->fn . ' ' . $this->ln;
);
}
}
class Lead extends Model
{
protected $fillable = [
'full_name'
];
public function client()
{
return $this->hasOne(Client::class, 'full_name', 'full_name');
}
}
As you can see, I try to build a relationship from the Lead
to the Client
model, so that I can use Lead::first()->client
. But my try looks for clients.full_name
what is not existing in the database.
How can I implement this relationship?
In tinker I proved, that there is a match:
> Lead::first()->full_name === Client::first()->full_name
= true