Route::get('', function() {
$s = RequestDiscussion::find(23721);
dd($s->user);
});
public function user()
{
return $this->hasOneThrough(
User::class,
Request::class,
'id',
'id',
'request_id',
'user_id');
}
public function user()
{
$instance = $this->newRelatedInstance(User::class);
$foreignKey = `request_discussions`.`request_id`;
$localKey = $this->getKeyName();
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey)->join('orders.requests', 'requests.user_id', '=', 'users.id');
}
DB::Connection('mysql')->table('request_discussions')
->leftJoin('requests', 'request_discussions.request_id', '=', 'requests.id')
->leftjoin((DB::Connection('mysql_u')->table('users')), 'requests.user_id', '=', 'users.id')
->get();
$database1 = config()->get('database.connections.mysql.database');
return $this->setConnection('mysql_u')->hasOne(
User::class,
'id',
'id',
'request_id',
'user_id')->join($database1.'.requests', 'requests.user_id', '=', 'users.id');
первое, 'mysql_u.requests' таким образом laravel не видит БД.
SQLSTATE[42000]: Syntax error or access violation: 1049 Unknown database 'mysql_u'
SELECT
*
FROM
`users`
INNER JOIN `mysql_u`.`requests` ON `requests`.`user_id` = `users`.`id`
WHERE
`users`.`id` = 23721
AND `users`.`id` IS NOT NULL
AND `users`.`deleted_at` IS NULL
limit
1
DB::table('request_discussions')
->leftJoin('requests', 'request_discussions.request_id', '=', 'requests.id')
->leftjoin('orders.users','requests.user_id','=','users.id')
->where('request_discussions.id', '=', 23721)
->get();
dd($this->setConnection('mysql_u')->hasOne(
User::class,
'id',
'id',
'request_id',
'user_id')->join('orders.requests', 'requests.user_id', '=', 'users.id')->toSql());
select * from `users`
inner join `orders`.`requests`
on `requests`.`user_id` = `users`.`id`
where `users`.`id` = ?
and `users`.`id` is not null
and `users`.`deleted_at` is null
public function user()
{
$instance = $this->newRelatedInstance(User::class);
$foreignKey = 'requests.id';
$localKey = 'request_id';
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey)->join('orders.requests', 'requests.user_id', '=', 'users.id');
}
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
{
return new HasOne($query, $parent, $foreignKey, $localKey);
}
select * from `users`
inner join `orders`.`requests`
on `requests`.`user_id` = `users`.`id`
where `requests`.`id` = ?
and `requests`.`id` is not null
and `users`.`deleted_at` is null
$foreignKey = `request_discussions`.`request_id`;
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'request_discussions.id' in 'where clause'
SELECT
*
FROM
`users`
INNER JOIN `orders`.`requests` ON `requests`.`user_id` = `users`.`id`
WHERE
`request_discussions`.`id` = 23721
AND `request_discussions`.`id` IS NOT NULL
AND `users`.`deleted_at` IS NULL
limit
1
$tables = [
'request_discussions' => 'request_id',
'requests' => 'user_id',
'users' => 'id'
];
Route::get('', function() {
$s = RequestDiscussion::find(23721);
dd($s->user);
});
public function user()
{
$instance = $this->newRelatedInstance(User::class);
$foreignKey = 'requests.id';
$localKey = 'request_id';
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey)->join('orders.requests', 'requests.user_id', '=', 'users.id');
}
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
{
return new HasOne($query, $parent, $foreignKey, $localKey);
}
public function request()
{
return $this->belongsTo(Request::class)->join('orders.users', 'users.id', '=', 'requests.user_id');
}
public function user()
{
return $this->hasOneThrough(
User::class,
Request::class,
'id',
'id',
'request_id',
'user_id');
}
public function user()
{
$instance = $this->newRelatedInstance(User::class);
$foreignKey = 'requests.id';
$localKey = 'request_id';
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey)->join('orders.requests', 'requests.user_id', '=', 'users.id');
}
select * from `users` inner join `orders`.`requests` on `requests`.`user_id` = `users`.`id` where `uid=1000(www) gid=1000(www) groups=1000(www)
` = ? and `uid=1000(www) gid=1000(www) groups=1000(www)
` is not null and `users`.`deleted_at` is null