我有产品和库存表;
制品
id int
name varchar
created_at timestamp
Run Code Online (Sandbox Code Playgroud)
个股
id int
name varchar
product_id varchar
created_at timestamp
Run Code Online (Sandbox Code Playgroud)
产品型号
public function validStock() {
return $this->hasMany('Stock')->where('quantity', '>', 10);
}
Run Code Online (Sandbox Code Playgroud)
如果两者都有created_at,如何通过stock的created_at订购,我尝试了两种方法,但它不起作用
Product::with('validStock')->orderBy('validStock.created_at', 'DESC');
Product::with(array('validStock' => function($q) {
$q->orderBy('created_at', 'DESC');
}));
Run Code Online (Sandbox Code Playgroud) name 'chan' value 'a'
name 'chan' value 'b'
name 'max' value 'a'
name 'max' value 'b'
name 'tony' value 'a'
name 'tony' value 'c'
Run Code Online (Sandbox Code Playgroud)
我需要找出用户谁都有价值a
和b
,这是我的解决方案:
SELECT * FROM `table`
GROUP BY `name`
HAVING SUM(IF(`value` = 'a', 1, 0)) >= 1 AND SUM(IF(`value` = 'b', 1, 0)) >= 1
Run Code Online (Sandbox Code Playgroud)
有更好的方法吗?
我有CartController路由过滤器似乎只能在控制器上绑定或获取,我可以对"动作"进行身份验证过滤吗?
例如:
<?php
CartController extends BaseController {
public function getIndex() {
// not need filter
}
public function getList()
{
// not need filter
}
public function getCheck()
{
// need to filter
}
}
Run Code Online (Sandbox Code Playgroud) var json = {name: 'chan'};
var variable = 'age';
$.extend(json, {[variable]: 35});
$('#result').html(JSON.stringify(json));
Run Code Online (Sandbox Code Playgroud)
该方法适用于除IE之外的大多数流行浏览器,我需要动态定义对象密钥,如何使其在IE上起作用?
document.querySelector('#share').onclick = function () {
var popup = window.open('http://www.facebook.com/sharer/sharer.php?u=http://www.google.com', '', "width=400, height=400");
popup.onbeforeunload = function() {
alert('unload');
}
return false;
};
Run Code Online (Sandbox Code Playgroud)
<a id="share" href="#">share</a>
Run Code Online (Sandbox Code Playgroud)
两件事情:
我想在用户完成facebook共享后做一些事情,如果我通过打开窗口共享页面,窗口将在一切完成后自动关闭,所以我想使用beforeload
事件来模仿after sharing callback
,但是当弹出窗口时我无法得到它关闭了.
如果用户只是关闭窗口或取消共享也会触发事件,所以这不是最好的解决方案,有没有facebook共享成功的回调api?