M
M
MOK4SS2020-11-04 18:39:02
Laravel
MOK4SS, 2020-11-04 18:39:02

How to write a query to get a result from another table?

There is a task:
5fa2c8eb647ff221589596.jpeg
I'm trying to do this:
Take the user's Auth and compare its value with the Auth of another table.
If the values ​​match, then display the amount of money for the current user.
So far the following has happened:

$auth = Auth::user()->auth;
 $lk = App\Models\Lk::select('cash','auth')->where('auth',$auth)->get();

But the $lk variable returns NULL .
Where am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pLavrenov, 2020-11-05
@pLavrenov

The cash field is not in the second table.
Relationships should be used https://laravel.com/docs/8.x/eloquent-relationships

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question