Y
Y
Yuri Dmitriev2018-08-06 11:32:29
Laravel
Yuri Dmitriev, 2018-08-06 11:32:29

How to properly get value from another Laravel table?

I must say right away that I am new to Laravel.

public static function getComments() {
    	$data = DB::table('comments')
    		->orderBy('id', 'desc')
    		->paginate(20);

    	return $data;
    }

With the getComments method, I get all the comments.
The table has a user_id field, tell me how, knowing the user_id, get the username from the Users table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
netrox, 2018-08-06
@BonifacyBel

If relationships are written in the model, then something like this:
https://laravel.com/docs/5.6/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question