问题:我有一个按预期工作的GROUP_CONCAT查询,除了我想使concat成为连接答案,而不是原始ID字段.
当前查询:
SELECT user.user_id, user.user, GROUP_CONCAT(user_roles.roleID separator ', ') roles
FROM user
JOIN user_roles ON user.user_ID = user_roles.user_ID
GROUP BY users.user_ID, users.user
Run Code Online (Sandbox Code Playgroud)
给出结果:
+----------+---------+----------------------------+
| user_ID | user | roles |
+----------+---------+----------------------------+
| 1 | Smith | 1, 3 |
+----------+---------+----------------------------+
| 2 | Jones | 1, 2, 3 |
+----------+---------+----------------------------+
Run Code Online (Sandbox Code Playgroud)
期望的结果:
+----------+---------+----------------------------+
| user_ID | user | roles |
+----------+---------+----------------------------+
| 1 | Smith | Admin, Other |
+----------+---------+----------------------------+
| 2 | Jones | Admin, Staff, Other | …Run Code Online (Sandbox Code Playgroud) Laravel 3上构建的应用程序是否适用于Laravel 4?
几天前,我找到了Laravel,现在我尝试学习它.当Laravel 4来临时,我是否会浪费时间学习Laravel 3?LV4中的一些插件是否相同?我的应用程序是否会在LV3中构建LV3?
在哪里以及如何开始学习LV4?
在laravel登录尝试我通常使用这样的东西:
if (Auth::attempt(array('email' => $usernameinput, 'password' => $password), true))
{
// The user is being remembered...
}
Run Code Online (Sandbox Code Playgroud)
基本上$usernameinput会email从我的桌子检查.
我在想这样做以不同的方式,像有email,username而且password在我的表.$usernameinput 可以是我表中的任何一个email 或username字段.
我怎样才能Auth::attempt满足以下条件:
(email==$usernameinput OR username==$usernameinput) AND password == $password
Run Code Online (Sandbox Code Playgroud) 我需要一个包含问题和答案的数据库.我想将这些问题和答案放在名为Post的同一个数据库表中.将有一个字段post_type,告诉我帖子是一个问题或答案.
我怎样才能在Laravel模型中实现这一目标?
谢谢.
我有简单的composer.json文件:
{
"require": {
"illuminate/routing": "4.1.*"
}
}
Run Code Online (Sandbox Code Playgroud)
和index.php:
<?php
require_once 'vendor/autoload.php';
$router = new Illuminate\Routing\Route();
$router->get('/', function(){
echo 'test';
});
Run Code Online (Sandbox Code Playgroud)
你还需要什么代码才能运行路由?
每当我运行任何php artisan命令时php artisan list,我什么也得不回来.没有命令可以工作.
我一直在寻找,并尝试了以下内容:
/root/.composer777bootstrap/compiled.php文件什么都没有app/storage/logs/log-cli-.txt.
我可以在浏览器中查看该网站.
我使用PHP v.5.5.11运行CentOS 6.3 64位 - Laravel 4.1
我是PHP和Laravel Framework的新手.我想在服务器端的Laravel中打印变量来检查它们包含的值.如何console.log在服务器上执行或打印变量值,以查看Laravel PHP中包含的变量值.
我在(梦幻般的)Laravel PHP框架上使用工匠时遇到了致命的错误.
我最近下载了Laravel的v3.2.1,并尝试在artisan所在的目录中运行以下命令行:
php artisan key:generate
Run Code Online (Sandbox Code Playgroud)
这应该在我的applications/application.php文件中为我创建一个随机密钥.(有关此命令的特定参考,请参阅http://laravel.com/docs/artisan/commands.)
但是,当我从shell运行此命令时,我收到以下错误:
Warning: chdir(): No such file or directory (errno 2) in /home/[USERNAME REMOVED]/websites/[DIRECTORY REMOVED]/htdocs/dev/sb4/paths.php on line 62
Parse error: syntax error, unexpected T_STRING in /home/[USERNAME REMOVED]/websites/[DIRECTORY REMOVED]/htdocs/dev/sb4/laravel/core.php on line 1
Run Code Online (Sandbox Code Playgroud)
这就是paths.php第62行的内容:
chdir(__DIR__);
Run Code Online (Sandbox Code Playgroud)
这是core.php的第1行:
<?php namespace Laravel;
Run Code Online (Sandbox Code Playgroud)
我的问题是:是否有任何特定的环境,目录或其他权限我应该修改以使工匠启动并运行.
一点背景:
我的环境:
我的根目录:(括号中的权限)
如果我的相关设置有任何其他详细信息,请告知我们.我真的不确定在解决此问题时有什么帮助.
-
更新:我还将此问题发布到Laravel的GitHub问题跟踪器.(https://github.com/laravel/laravel/issues/820)
我正在使用像这样的laravel查询生成器.
$col1 = Input::get('col1','');
$col2 = Input::get('col2','');
$result = DB::table('table1')
->select('id', 'col1', 'col2', 'col3')
->whereRaw("col1 like '%?%'", [$col1])
->whereRaw("col2 like '%?%'", [$col2])
->orderBy($orderBy, $orderType) //orderBy=col1, ordeyType=ASC
->skip($ofset)->take($limit) //$ofser=0, $limit=10
->get();
Run Code Online (Sandbox Code Playgroud)
我一无所获.如果我使用toSql()函数.我这样得到这个SQL
select `id`, `col1`, `col2`, `col3`
from `table1` where col1 like '%?%' and col2 like '%?%'
order by `col1` ASC limit 10 offset 0
Run Code Online (Sandbox Code Playgroud)
问号不应该存在.它必须用值替换它们.我用这段代码来调试它.
Log::info(var_export(DB::getQueryLog(), true));
Run Code Online (Sandbox Code Playgroud)
日志看起来像这样
2 =>
array (
'query' => 'select `id`, `col1`, `col2`, `col3` from `table1` where col1 like \'%?%\' and col2 like \'%?%\' order …Run Code Online (Sandbox Code Playgroud) 更新:
当我在Laravel 4工作时,我的退出操作有问题,但是在laravel 4.1中我有这个错误:
Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute(),
called in
C:\Users\mohammed\workspace\mylittlebiz\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 2432 and defined
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
public function doLogout()
{
Auth::logout(); // log the user out of our application
return Redirect::to('login'); // redirect the user to the login screen
}
Run Code Online (Sandbox Code Playgroud)
这是我的模特:
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $hidden = array('password');
/**
* Get …Run Code Online (Sandbox Code Playgroud) laravel ×9
laravel-4 ×7
php ×6
laravel-3 ×3
composer-php ×1
frameworks ×1
group-concat ×1
mysql ×1