Q:

How to make a connection between 2 tables?

I need to get profile_picture from table users, based on user_id from table log, but everything what I used was wrong.Can you help me with this code?
Here is my model
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Log extends Model
{
    protected $table = 'logs';

    public $timestamps = false;

    use SoftDeletes;
    // protected $softDelete = true;

    protected $fillable = [
        'user_id','log','date','type','article_type', 'formatted_date','link','action_user_id','action_name','action_username','item_id'
    ];

    public function user()
{
    return $this->belongsTo(User::class, 'user_id');
}
}

Here is my view
@foreach($users as $user)

<img style="margin-right: 10px" src="{{ asset('thumbnail') }}/{{ $user->profile_picture }}" alt="">
@endforeach 

Here is my controller
public function myAlerts($page = null)
{
$users =  \App\Log::with('users')
            ->where('user_id', '=', 'profile_picture')
            ->get();
}         

But I got this error: Call to undefined method Illuminate\Database\Query\Builder::users()

A:

You made user method in model and you're calling users
public function myAlerts($page = null){
    $users =  \App\Log::with('user')->get();
}  

If you want to check $user id then you can check like
public function myAlerts($page = null){
    $userid = 5;

    $users =  \App\Log::with('user')->wherehas(['user'=>function($q) use($userid) {
        $q->where('id',$userid);
    }])->get();
}  

