Laravel 4 Laravel db:table()返回空集
我不熟悉PHP和Laravel。我遵循LaraCast教程,它创建了一个简单的用户表。然后,route函数获取所有用户并返回浏览器。我可以在in db中看到数据,但通过Laravel路由,结果总是空的。在创建数据库、表等之后,是否需要重新启动任何操作?谢谢你的帮助 Routes.phpLaravel 4 Laravel db:table()返回空集,laravel-4,eloquent,Laravel 4,Eloquent,我不熟悉PHP和Laravel。我遵循LaraCast教程,它创建了一个简单的用户表。然后,route函数获取所有用户并返回浏览器。我可以在in db中看到数据,但通过Laravel路由,结果总是空的。在创建数据库、表等之后,是否需要重新启动任何操作?谢谢你的帮助 Routes.php Route::get('/', function(){ $users = DB::table('users')->get(); return $users; }); Database.p
Route::get('/', function(){
$users = DB::table('users')->get();
return $users;
});
Database.php
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'awesomeproject',
'username' => 'homestead',
'password' => '***',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
当我点击时,我得到[]作为回应
mysql
config/local/app.php
中的debug
是否设置为true
app/config/local/database.php中的连接凭据,而不是app/config/database.php
。如果您使用的是Homestead,则您的app/config/local/database.php
应该如下所示:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
如果您没有在
app/config/local/database.php
中设置凭据,则当您认为您正在查询awesomeproject
数据库时,可能正在从homestead
数据库中提取结果。是。我用流浪者的家园来建立我的环境,因为我想尽快开始。为了检查,我还使用了“root”作为用户名,它还返回一个空集。有什么调试方法吗?编辑database.php的本地副本修复了错误。我下面的课程不使用homestead,他们配置了app/config/database.php。homestead数据库也恰好有一个空的用户表:(。谢谢您的回答!
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),