[英]complex Query Builder in Laravel 5.5?
Hello I have a raw query that's look like this and have to transform in query builder in Laravel 5.5 without using eloquent and need to have pagination 您好,我有一个原始查询,看起来像这样,必须在Laravel 5.5的查询生成器中进行转换,而无需雄辩,并且需要分页
select lt.country_name, u.user_id, u.real_name from users u
join lang_table lt on lt.language_id = u.country
where not exists (select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1) and not exists(select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1)
and u.user_id <> 1
and u.country = 1
trying a lot of variants like this below but every time give me an error if someone can help me? 在下面尝试许多这样的变体,但是每次有人提供帮助时都会给我一个错误?
$data = DB::table('users')
->join('lang_table','lang_table.language_id', '=' ,'users.country')
->select('lang_table.country','users.user_id','users.real_name')
->select(DB::raw(where not exists (select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1) and not exists(select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1)
and u.user_id <> 1
and u.country = 1))
->paginate(25);
Try to change strict to false in config\\database.php 尝试在config \\ database.php中将strict更改为false
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', ''),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
I managed to write this request and now gives me the following error 我设法写了这个请求,现在给我以下错误
Type error: Argument 1 passed to Illuminate\\Database\\Connection::prepareBindings() must be of the type array, null given, called in C:\\xampp\\htdocs\\findfriends\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php on line 665 类型错误:传递给Illuminate \\ Database \\ Connection :: prepareBindings()的参数1必须为数组类型,给定为null,在C:\\ xampp \\ htdocs \\ findfriends \\ vendor \\ laravel \\ framework \\ src \\ Illuminate \\中调用665行上的Database \\ Connection.php
DB::select(`lt.country_name`,`u.user_id`,`u.real_name`)
->from(`users as u`)
->join(`lang_table as lt`, function($join) {
$join->on(`lt.language_id`, `=`, `u.country`);
})
->whereRaw(`not exists`, [], `( select fr2 from friends where fr1 = 1 and fr2 = u.user_id and status = 1 )`)
->whereRaw(`not exists ( select fr1 from friends where fr2 = 1 and fr1 = u.user_id and status = 1 )`, [], `and`)
->where(`u.user_id`, `<>`, 1)
->where(`u.country`, `=`, 1)
->paginate(25);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.