To filter the relation between two models that are connected to different databases, you can use the with method and pass a closure to it. Inside the closure, you can specify the conditions for the relation using the where method. Here's an example:
$logEntries = LogEntry::with(['user' => function ($query) use ($userId) {
$query->where('id', $userId);
}])->get();
In this example, LogEntry is the model for the log entries table, and user is the relation to the users table in the other database. The closure passed to with specifies that we only want log entries that are related to the user with the given $userId.
Note that you need to use the fully qualified class name for the related model in the closure, like this:
use App\Models\OtherDatabase\WebAppUser;
$logEntries = LogEntry::with(['user' => function ($query) use ($userId) {
$query->where('id', $userId);
}])->get();
This assumes that the WebAppUser model is in the App\Models\OtherDatabase namespace.