我一直在使用Eloquent ORM已经有一段时间了,我知道它非常好,但我不能做到以下几点,而在Fluent中很容易做到.
我的用户有多对多的歌曲,中间表是song_user(就像它应该的那样).根据播放次数判断,我想获得用户的热门歌曲.当然,播放计数存储在中间表中.
我可以用Fluent做到:
$songs = DB::table('songs')
->join('song_user', 'songs.id', '=', 'song_user.song_id')
->where('song_user.user_id', '=', $user->id)
->orderBy("song_user.play_count", "desc")
->get();
Run Code Online (Sandbox Code Playgroud)
简单.但我想在Eloquent中做到这一点,当然这不起作用:
$songs = Song::
with(array("song_user" => function($query) use ($user) {
$query->where("user_id", "=", $user->id)->orderBy("play_count", "desc");
}))
Run Code Online (Sandbox Code Playgroud) 帮我理解泛型.假设我有两个枚举作为内部类,如下所示:
public class FoodConstants {
public static enum Vegetable {
POTATO,BROCCOLI,SQUASH,CARROT;
}
public static enum Fruit {
APPLE,MANGO,BANANA,GUAVA;
}
}
Run Code Online (Sandbox Code Playgroud)
不是让两个枚举实现接口,而是必须两次实现相同的方法,我希望在外部类中有一个方法,它可以执行以下操作:
public <e> String getEnumString<Enum<?> e, String s) {
for(Enum en: e.values()) {
if(en.name().equalsIgnoreCase(s)) {
return s;
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
但是这种方法不能编译.我想要做的是找出一个字符串值是否是枚举值的名称,在任何枚举中,是否是蔬菜,水果,什么不是.无论这实际上是否是一种冗余方法,我试图(重新)编写的那个有什么问题?
基本上我想这样做:
public class FoodConstants {
public static enum Vegetable {
POTATO,BROCCOLI,SQUASH,CARROT;
}
public static enum Fruit {
APPLE,MANGO,BANANA,GUAVA;
}
public <e> String getEnumString<Enum<?> e, String s) {
for(Enum en: e.values()) {
if(en.name().equalsIgnoreCase(s)) {
return s;
}
} …Run Code Online (Sandbox Code Playgroud) 我需要帮助关闭此功能,如果可能的话,从交互模式或我会发疯.如果你想要这个值,REPL会在每个表达式之前坚持等号.我发现这非常刺激和不直观.更糟糕的是,如果你错误地忘记了等号,它会带你进入这个辅助提示,只有输入一个会导致错误的表达式才能退出.
*** str="This is some string"
*** str
>>
>>
>> =
>>
>> =str
stdin:6: unexpected symbol near '='
*** =str
This is some string
*** #str
stdin:1: unexpected symbol near '#'
*** =#str
19
***
*** 545+8
stdin:1: unexpected symbol near '545'
*** =545+8
553
***
Run Code Online (Sandbox Code Playgroud)
我需要一个使用REPL的教训:
有没有办法摆脱等号,这样它的行为就像其他REPL一样?
如果不做我做的事情,你如何退出辅助提示?
我想为我的网站运行一个带有凤凰后端的angularJS前端.我希望我的根路由将用户引导到包含我的角度客户端的静态目录中的预构建页面,然后使用phoenix运行API.过去我通过路由匹配在轨道上使用ruby来完成此操作:
get '/', to: redirect('/foobar.html')
Run Code Online (Sandbox Code Playgroud)
有没有办法和凤凰做类似的事情?
我刚刚在Lua使用了modulo(%),我注意到它出于某种原因非常不准确.我在"魔兽世界"中使用它,但我认为它至少在某种程度上是最新的.
无论如何,使用以下示例,输出将为1;
print((0.6/(0.1^(2-1)))%1)
Run Code Online (Sandbox Code Playgroud)
但是当我使用以下内容时,它将返回0;
print((0.6*(10^(2-1)))%1)
Run Code Online (Sandbox Code Playgroud)
就我受过教育而言,0.6/0.1应相当于0.6*10.
这不是一个问题或问题,但我只是对原因感到好奇.在我看来,数学中的不准确性会非常具有破坏性.
遍布网络的Lua教程显示使用lua_register()来公开扩展DLL中实现的函数:
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static int pushlua3(lua_State *L)
{
lua_pushnumber(L, 3);
return 1;
}
int luaopen_lua3pushbinder(lua_State *L)
{
lua_register(L,"pushlua3", pushlua3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
lua_register() 是宏而不是函数,这是来自5.2手册:
http://www.lua.org/manual/5.2/manual.html#lua_register
[-0,+ 0,e]
Run Code Online (Sandbox Code Playgroud)void lua_register (lua_State *L, const char *name, lua_CFunction f);将C函数f设置为全局名称的新值.它被定义为一个宏:
Run Code Online (Sandbox Code Playgroud)#define lua_register(L,n,f) \ (lua_pushcfunction(L, f), lua_setglobal(L, n))
如果你单独使用这些函数,lua_pushcfunction很好,但是lua_setglobal崩溃了,因为它试图引用LUA_GLOBALSINDEX并且在运行时失败,而不是编译时.
那么现在实现lua_register()的正确方法是什么?
我有点想到,当Lua移动到5.2并重新使用LUA_GLOBALSINDEX和lua_register()表示的概念时,更改lua_register()以便它以"新"方式执行它是合理的.
那么,有没有Ubuntu没有为lua5.2选择的标题更新?我应该有一个指向的路径,/usr/include/lua5.2然后我不会遇到这个问题?我的盒子上只有一个Lua 5.1 include目录.
tnx可以提供任何帮助.
我正在运行 ubuntu 并安装了 luarocks,但是,每当我尝试安装类似 luasocket (luarocks install luasocket) 之类的东西时,它都会抛出以下错误:
错误:找不到 Lua 库失败。您可能需要配置 LUA_LIBDIR
我的两个配置文件如下所示:
rocks_trees = {
{ name = "user", root = home .. "/.luarocks" };
{ name = "system", root = "/usr/local" };
}
lua_interpreter = "lua5.3";
variables = {
LUA_DIR = "/usr/include/lua53";
LUA_BINDIR = "/usr/bin/lua53";
Run Code Online (Sandbox Code Playgroud)
}
任何帮助表示赞赏!
我有一些在Linux机器上开发的PHP文件,我现在在Mac上工作(OS 10.8.2).即使在Linux机器上正确显示页面,Mac上的页面也没有正确显示.经过一番调查后,我发现这是因为它没有识别出这样的语法:
<?=$var ?>
Run Code Online (Sandbox Code Playgroud)
任何以a开头<?而不是<?php(不仅仅是上面的var快捷键,任何代码块)的东西都被解释为纯文本,而不是PHP.在Linux开发盒和生产服务器上,<?可以很好地识别快捷语法.我认为这是我在安装过程中遗漏的配置,所以我错过了什么?我可以配置我的Mac来识别这种语法吗?
mac正在运行PHP 5.3.15.开发框运行较早5.*.我不知道生产服务器上的版本.