There are two tables users and posts

There is a user_id column in user_id

How to get all the information about users by user_id and that it would be tied to your posts

Ie the code is as follows:

 @foreach($posts as $post) <div class="content" data-postid="{{ $post->id }}"> <header>{{ $post->title }}</header> <div class="body">{{ $post->body }}</div> <div class="info"> Дата: {{ $post->created_at->format('dm-Y') }} *инфа о пользователе* </div> </div> @endforeach 

    1 answer 1

    Thank you, I decided my question. Who cares:

     //Post public function user(){ return $this->belongsTo('App\User'); } //View $post->user->whatEverUserInfo; 
    • And immediately make a selection with with Post::with('users') otherwise you will go to the database for each iteration in the loop. - SlyDeath
    • Yes, I initially saw this in the documentation and did it, but thanks for warning) - MoDDem