现在无法使用Laravel查询构建器进行此类查询(使用绑定):
SELECT * FROM `posts` WHERE MATCH( `title`, `description` AGAINST( 'bar' IN BOOLEAN MODE)) ORDER BY (MATCH( 'title' AGAINST( 'bar' )) DESC;
Run Code Online (Sandbox Code Playgroud)
这将按相关性排序结果,如果我们(现在我们没有!)orderByRaw那么上面的查询将是:
Post::whereRaw("MATCH( `title`, `description` AGAINST( ? IN BOOLEAN MODE))", array('bar'))->orderByRaw("(MATCH( 'title' AGAINST( ? )) DESC", array('bar'))->get();
Run Code Online (Sandbox Code Playgroud)
我打开了这个问题,但它无处可去:https: //github.com/laravel/framework/issues/2134
有什么建议吗?
我们在我们的网站上遇到过这个问题,我们从用户那里得到了CSRF错误.会话cookie和会话数据设置为在12小时内过期,会话驱动程序设置为使用Redis.在我们的调查之后,我们最终成功地模拟了异常情况,所以这里是场景:
用户在网站上打开两个不同的页面,使用Chrome浏览器打开"打开上次关闭的标签"设置.其中一个页面上有一个表单(例如登录),然后用户在某个时刻退出浏览器.他第二天重新打开浏览器(12小时过去,因此会话cookie和会话数据已过期)Chrome尝试重新加载所有打开的页面.它向服务器发送两个同时发出的请求,而它们都没有会话cookie.在服务器端,Laravel为每个会话ID生成两个不同的会话ID.Chrome接收它们并覆盖其他会话cookie上的一个.一旦用户尝试提交表单(例如登录),它就会在表单会话cookie被覆盖时生成CSRF错误.
我们还有一些AJAX帖子请求,由于这种情况我们失败了CSRF错误.
我想知道Laravel是否能够以安全的方式为两个请求生成相同的会话ID.
有没有人有任何想法我们如何解决这个问题?
PS:我们正在使用laravel 4.1和这个会话配置:
return array(
'driver' => 'redis',
'lifetime' => 720,
'expire_on_close' => false,
'files' => storage_path().'/sessions',
'connection' => null,
'table' => 'sessions',
'lottery' => array(2, 100),
'cookie' => 'laravel_session',
'path' => '/',
'domain' => '.ourdomain.com',
);
Run Code Online (Sandbox Code Playgroud) 我只想运行这样的查询:
select * from `users` where SUBSTRING_INDEX(`email`, '@' ,-1) not in ('gmail.com, outlook.com');
Run Code Online (Sandbox Code Playgroud)
有两种方法使我无法解决:
$providers = array('gmail.com', 'outlook.com');
$providers = "'" . implode("', '", $providers) . "'";
User::whereRaw("SUBSTRING_INDEX(`email`, '@' ,-1) not in (?)", $providers);
Run Code Online (Sandbox Code Playgroud)
上面的方法不起作用,因为PDO将转义“'”字符。
User::whereIn(DB::raw("SUBSTRING_INDEX(`email`, '@' ,-1)", $providers);
Run Code Online (Sandbox Code Playgroud)
这根本行不通。任何的想法?
我正在尝试使用角度与django我实现了一个REST api与django tastypie,这里是角度资源的代码:
angular.module('CourseServices', ['ngResource']).
factory('Course', function($resource){
return $resource('api/v1/course/:courseId/?format=json', {}, {
query: {method:'GET', params:{courseId:'1'}, isArray:true}
});
});
Run Code Online (Sandbox Code Playgroud)
这是我想要的地方:
var course = Course.get({courseId:$routeParams.courseId});
console.log(course);
Run Code Online (Sandbox Code Playgroud)
此代码在浏览器中记录:
Resource
course_pic: "http://localhost:8000/media/course_pics/2012/10/24/Apple-Launches-Genius-Recommendations-for-Apple-TV-2.png"
creation_time: "2012-10-24T06:28:11+00:00"
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed faucibus cursus mi, in laoreet dolor placerat vitae. ."
id: "1"
instructor: "/api/v1/user/1/"
name: "Computation Theory"
resource_uri: "/api/v1/course/1/"
subscribers: 0
update_time: "2012-10-24T06:28:11+00:00"
__proto__: Resource
Run Code Online (Sandbox Code Playgroud)
所以我有我想要的数据,但当我尝试访问我的控制器中的"course.id"时,我得到了未定义!我不知道为什么!REST服务器响应是json.