我有以下Eloquent查询(这是一个查询的简化版本,它由更多的wheres和orWheres 组成,因此显而易见的迂回方式 - 理论是重要的):
$start_date = //some date;
$prices = BenchmarkPrice::select('price_date', 'price')
->orderBy('price_date', 'ASC')
->where('ticker', $this->ticker)
->where(function($q) use ($start_date) {
// some wheres...
$q->orWhere(function($q2) use ($start_date){
$dateToCompare = BenchmarkPrice::select(DB::raw('min(price_date) as min_date'))
->where('price_date', '>=', $start_date)
->where('ticker', $this->ticker)
->pluck('min_date');
$q2->where('price_date', $dateToCompare);
});
})
->get();
Run Code Online (Sandbox Code Playgroud)
你可以看到我pluck在我之前或之后发生的最早日期start_date.这会导致运行单独的查询以获取此日期,然后将其用作主查询中的参数.有没有一种方法可以将查询嵌入到一起形成子查询,从而只有1个数据库调用而不是2个?
编辑:
根据@ Jarek的回答,这是我的查询:
$prices = BenchmarkPrice::select('price_date', 'price')
->orderBy('price_date', 'ASC')
->where('ticker', $this->ticker)
->where(function($q) use ($start_date, $end_date, $last_day) {
if ($start_date) $q->where('price_date' ,'>=', $start_date);
if ($end_date) $q->where('price_date' ,'<=', $end_date);
if ($last_day) …Run Code Online (Sandbox Code Playgroud) 我正在使用jQuery Select2(v4)插件作为标签选择器.
我想监听在select元素中创建新标记的时间,并激活ajax请求以存储新标记.我发现有createTag事件,但每次在select2元素中输入一个字母时,这似乎都会触发.如我的小提琴所示:http://jsfiddle.net/3qkgagwk/1/
是否有类似的事件仅在新标签输入完毕后才会触发?也就是说它被一个封闭它的灰色盒子所包围.
I'm getting some strange behaviour in Node when making a request to locally running server.
我有一个本地服务器侦听端口 4000。当使用node-fetch(或任何其他 Node fetch 实现)时,我ECONNREFUSED在向它发出请求时收到错误:
> fetch('http://localhost:4000')
Promise {
<pending>,
[Symbol(async_id_symbol)]: 345,
[Symbol(trigger_async_id_symbol)]: 5
}
> Uncaught TypeError: fetch failed
at Object.processResponse (node:internal/deps/undici/undici:5575:34)
at node:internal/deps/undici/undici:5901:42 {
cause: Error: connect ECONNREFUSED ::1:4000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 4000
}
}
Run Code Online (Sandbox Code Playgroud)
我可以愉快地使用 或 Web 浏览器向该服务器发出请求,curl不会出现错误(尽管它看起来像是在 IPv4 之前尝试 IPv6): …
当我在MS Access中运行查询时,我可以愉快地使用这样的查询:
SELECT clients.* FROM clients WHERE active=True;
Run Code Online (Sandbox Code Playgroud)
要么
SELECT clients.* FROM clients WHERE active=-1;
Run Code Online (Sandbox Code Playgroud)
但不是
SELECT clients.* FROM clients WHERE active=1;
Run Code Online (Sandbox Code Playgroud)
另外,假设我想使用PDO查询数据库,我可能会使用预准备语句:
$db->prepare('SELECT clients.* FROM clients WHERE active=:isactive;');
$db->bindValue(':isactive', True); //Does not work
$db->bindValue(':isactive', 1); //Does not work
$db->bindValue(':isactive', -1); //Does work
Run Code Online (Sandbox Code Playgroud)
因此,即使true在向Access发送普通查询时工作,如果仅绑定-1或0将适用于布尔值.
这是为什么,为什么-1代表true时1通常意味着true在其他语言/数据库?
我有2个型号,Client和Security.它们与HATBTM关系相关联.我做了一个名为的连接表clients_securities.所以一个Client可以拥有许多证券,一个Security可以属于许多证券Client.

这是我的关系定义:
//Client Model:
public $hasAndBelongsToMany = array(
'Security' =>
array(
'className' => 'Security',
'joinTable' => 'clients_securities',
'foreignKey' => 'client_id',
'associationForeignKey' => 'security_id',
'unique' => true,
)
);
//Security Model:
public $hasAndBelongsToMany = array(
'Client' =>
array(
'className' => 'Client',
'joinTable' => 'clients_securities',
'foreignKey' => 'security_id',
'associationForeignKey' => 'client_id',
'unique' => true,
)
);
Run Code Online (Sandbox Code Playgroud)
然后,我在客户端控制器中进行了编辑操作并执行了以下操作:
public function edit($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid client')); …Run Code Online (Sandbox Code Playgroud) 我想根据各种变量的条件追加一个带数字的数组.这是我提出的代码:我从一个空数组开始.
Sub makeArr()
Dim myArr() As Integer
If box1 = True Then
ReDim Preserve myArr(LBound(myArr) To UBound(myArr) + 1)
myArr(UBound(myArr)) = 1
End If
If box2 = True Then
ReDim Preserve myArr(LBound(myArr) To UBound(myArr) + 1)
myArr(UBound(myArr)) = 2
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
显然这是一个例子,所以不是最优雅的方式,但它不起作用,因为我似乎无法重新调整数组,因为它最初没有ubound或一个lbound.当我调暗它时,myArr(0 to 0)这也失败了.
有任何想法吗?
我有一个简单的1系列条形图,每个条形图都有一个标称值.我可以使用数据标签和轴来表示每个条形图的值,但是我希望数据标签和轴显示系列总数的百分比,而标称值显示在悬停的工具提示中(因此我不想在绘图之前将数据转换为百分比).
这是一张图片,展示了我现在和我现在所处的位置:

以下是我目前对轴标签作为格式化程序功能的内容:
plotOptions: {
bar: {
dataLabels: {
enabled: true,
formatter: function(){
return Highcharts.numberFormat(this.y,0);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
formatter我可以用一些函数变量来实现吗?我知道它很容易在饼图上完成,但我觉得条形图代表数据更好.
编辑:简单来说,我如何获得所有系列的积分?一旦我有了这个,就可以直接获得百分比:
return Highcharts.numberFormat(100 * this.y / this.y.total,0) + "%";
哪个this.y.total是系列的总和.
使用Laravel时,我知道使用composer在项目中使用第三方库需要遵循的步骤:
将包添加到composer.json:
"require": {
"zizaco/confide": "3.2.x"
}
运行composer update以安装包
config/app.php我试图用highchartsphp做同样的事情.通过composer安装很简单,但没有关于如何在Laravel中使用此软件包的说明.如何加载正确的文件以及如何实现自述文件中描述的类?这只是将它添加到提供者和别名然后$chart = new HighChart();在我想要的任何地方进行的情况吗?
好的,这实际上有点复杂.
我有一个列表项目设置的导航列表inline-block.项目数是列表是动态的,因此可能会有所不同.
我的目标是让列表项跨越容器的整个宽度.(例如,如果有4个列表项,每个列表项占据容器宽度的25%[忽略边距/填充等])
还有一个复杂的问题是,浏览器似乎为内联块元素添加了4px的余量,其中它们之间有空格(换行符/空格等).
我做了一个小提琴作为起点,有两个例子:第一个是内联块模式中的列表项,第二个证明它们在宽度上对齐.
既没有实现我想要的东西,整个宽度被元素占据而没有它们分成另一条线.
编辑:稍微分开,但为什么在我的第二个例子中lis 下方有一个空格,请注意我将行高和字体大小设置为0的事实?
我有一个使用Gulp的项目.我将我的项目部署到我的Ubuntu服务器上,现在想要编译资产(这是我目前所有的gulpfile).安装了Node和npm后,我npm install从项目的root 运行以安装依赖项.package.json的内容如下:
...},
"devDependencies": {
"bower": ">=1.3.12",
"gulp": "^3.8.10",
"gulp-concat": "^2.4.3",
"gulp-less": "^2.0.1",
"gulp-minify-css": "^0.4.3",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.1.0"
}...
Run Code Online (Sandbox Code Playgroud)
然后检查node_modules我的项目根目录中的文件夹,我可以看到每个依赖项的目录,表明它们已安装.但是,当我运行时,gulp我得到npm错误,如下所示:
Error: Cannot find module 'through2'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Run Code Online (Sandbox Code Playgroud)
这些似乎是我项目的依赖项的依赖项(因为它们没有在我的gulp文件中引用),但为什么没有安装它们?
我可以在出现错误时手动安装每个错误,但是我会在下一个缺失的依赖项中遇到另一个类似的错误.
我怎么解决这个问题?