在Laravel 4.2中,我有一个名为Product的模型,与其他模型(如Country或Category)有多对多的关系.我想过滤掉"不完整"的产品,这意味着它们没有连接的国家或没有连接的类别.我可以使用whereDoesntHave()方法来过滤掉一个关系.当我在一个查询中使用它两次时它会创建AND条件,但我需要OR.我orWhereDoesntHave()在API文档中找不到方法.我不能将多个关系作为参数传递,因为它期望第一个参数是一个字符串.
我需要这样的东西:
$products = Product::whereDoesntHave('categories')->orWhereDoesntHave('countries')->get();
有没有办法达到whereDoesntHave()多种OR条件?
我不明白为什么我的迁移在 Laravel 8 的全新安装中失败。这就是我得到的:
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = bunny and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674? // If an exception occurs when attempting to run a query, we'll format the error
675? // message to include the bindings with SQL, which will make this exception a
676? // lot more helpful to the developer instead of just the database's errors. …Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel5.0.我想添加paginate()到我的控制器部分的以下功能.
public function index()
{
try{
$val=DB::connection()->getDatabaseName();
if(DB::connection()->getDatabaseName()) {
//$bRecord = DB::table('bills')->orderBy('Date', 'desc')->paginate(4);
$bRecord = DB::table('bills')
->join('clients', 'bills.ClientID', '=', 'clients.ClientID')
->select('bills.ReceiptID', 'bills.ClientID', 'bills.Paid', 'bills.Date','bills.ReceivedBy',
'clients.ClientName')
->get();
return view('bills.billRecord')->with('bRecord', $bRecord);
}else{
$er="/connection status: database error";
return view('home')->with('error',$er); //'error' is passed to home
}
}catch (\Exception $e){
$er="/connection status: database error";
return view('home')->with('error',$er);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在这里添加paginate,它会显示错误."在数组上调用成员函数paginate()"
$bRecord = DB::table('bills')
->join('clients', 'bills.ClientID', '=', 'clients.ClientID')
->select('bills.ReceiptID', 'bills.ClientID', 'bills.Paid', 'bills.Date','bills.ReceivedBy',
'clients.ClientName')
->get()->paginate(4);
Run Code Online (Sandbox Code Playgroud)
我怎么paginate()在这里使用?