V
V
Volodymyr2021-02-02 19:26:10
Laravel
Volodymyr, 2021-02-02 19:26:10

How to use Relationship if some column values ​​of one table are different from another?

Hello!

In the User model, like this:

public function phones() {
        return $this->hasOne('App\Models\Phone', 'phone', 'phone');
    }

In the Phone model, like so:
public function users() {
    return $this->belongsTo('App\Models\User', 'phone');
}

I get data like this:
$userWP = $this->user->whereNotNull('phone')->with('phones')->get();

As a result, if in the phones table, in the phone column, there is a normal phone format (+7 (XXX) XXX-XX-XX), the same as in the User table, in the phone column, then the data is displayed, but if in the phones table, in the phone column will be the phone number with an added label, such as: AD-+7(XXX)XXX-XX-XX, then the data is not displayed.
Is it possible to somehow add a like type check to Relationship?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question