我是PHP和Laravel的新手。我正在關注LaraCast教程,它創建了一個簡單的用戶表。路由功能然後獲取所有用戶並返回到瀏覽器。我可以在db中看到數據,但Laravel路由的結果總是空的。創建數據庫,表格等後需要重新啓動嗎?謝謝你的幫助。Laravel db:table()返回空集
routes.php文件
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' => '',
),
當我打http://awesome.app:8000/我得到的[]作爲迴應。
MySQL的
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| awesomeproject |
| homestead |
| mysql |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)
mysql> use awesomeproject
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------+
| Tables_in_awesomeproject |
+--------------------------+
| users |
+--------------------------+
1 row in set (0.00 sec)
mysql> select * from users;
+----------+---------------+
| username | password |
+----------+---------------+
| ulidder | skjdfsjkhsdfs |
| user2 | dslfjasdfhw |
+----------+---------------+
2 rows in set (0.00 sec)
是的。因爲我想快速入門,所以我用流浪漢建立了自己的環境。只是爲了檢查,我還使用「root」作爲用戶名,它也返回一個空集。任何方式來調試? – 2014-11-08 22:11:09