I wanna query the users who created at 2016-01-10. So code in Laravel 5.1 like this:
$day1 = new Carbon();
$day1->year = 2016;
$day1->month = 1;
$day1->day = 10;
$day2 = new Carbon();
$day2->year = 2016;
$day2->month = 1;
$day2->day = 11;
User::whereBetween('created_at', [$day1->startOfDay(), $day2->startOfDay()])->get();
The codes above works fine. But this normally way, does not:
User::whereBetween('created_at', [$day1->startOfDay(), $day1->endOfDay()])->get();
So what is the problem? thanks a lot.
最近测试Jquery插件select2 多数功能都可以实现,但是Ajax始终没办法实现。若是有同学用过,请传授下。
我要实现城市名称的自动完成,类似携程或者去哪儿填写目的地一样。
前端JS代码
$(".js-data-example-ajax").select2({
ajax: {
type: 'POST',
url: "https://ajax.dev", //这是我的测试地址,已经更改Host
dataType: 'json',
delay: 200,
headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
data: function (params) {
return {
location: params.term,
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 2,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
服务器Laravel Controller 代码
public function ajax(Request $request){
$keywords=$request->term;
$result=DB::table('locations')->where('name','like',"%$keywords%")->get();
return $result;
}
好吧,可能我没说清楚,但是我从Github已经找到了建议的配置文件。
Hey大伙儿早上好。
我的服务器是Ubuntu, nginx + PHP FastCGI + MySQL 5.6
MySQL的配置是默认的cnf,我只修改了bind 127.0.0.1,让他绑定本地。
但是经常出现连接过多的情况,但通常当时并没有多少并发,从用户的角度,一定少于10人。请问有什么建议吗?这个问题弄得我相当郁闷。
谢谢。
返回的是数组,array(0)
举个例子,我有是个电话号码,只有一个是170
开头的,电话不在主键,所以我没办法直接用Eloquent::find($id)
的方式查找,即便可以,这种方式也是准确查找的。
而我希望是模糊判断。
如果用
$user=User::where('phone',"like","%170%")->first();
有当然直接返回集合,如果没有呢的话,也是个集合。
我没办达到判断是否有170
这个号段的模糊查找需求。
请问有好的办法吗?
@charlie 如果参考Between方法,那么应该是这么写
$todaystart=Carbon::now()->now()->startOfDay();
$todayend=Carbon::now()->now()->endOfDay();
User::whereBetween('created_at', [$todaystart,$todayend])->get();
我按照你的思路@JellyBool 我找到了解决办法。
但是今天的函数正确表达应该介于
Carbon\Carbon::now()->startOfDay();
Carbon\Carbon::now()->endOfDay();
@charlie 你的写法报错。@JellyBool 你的写法可以满足我的要求,但是我不明白,我的写法虽然不报错,但是没有获得我要的东西呢?
请问,我怎么从Eloquent查询当日的所有数据?
我试过
$today=Carbon\Carbon::now()->day;
$users = User::where('created_at','=',$today);
var_dump($today);
无效。