【发布时间】:2014-01-08 11:19:37
【问题描述】:
我是laravel的菜鸟,今天刚拿起它,看似简单的任务却让人头疼。
我正在学习 Jeffery Way 的教程,我们为数据库播种,下一步是创建控制器并获取资源。我生成了必要的文件,然后按照这些基本步骤操作。
数据库表为'players'
第一步。
//Here is the index() function inside my PlayersController.php
class PlayersController extends \BaseController {
public function index()
{
return Player::all();
}
}
第 2 步。
//Inside the app/models/ directory I create a file called Player.php
//Here is the code inside Player.php
class Player extends Eloquent {
protected $table = 'players' // I tried without the protect aswell
}
第 3 步。
//Finially a route
Route::resource('players', 'PlayersController');
Route::get('/', function()
{
return View::make('hello');
});
为了额外的措施,我还在命令行中运行了 composer dump-autoload,位于我的 laravel 项目的根目录中。
然后我没有告诉我路由在哪个目录,因为它是一个索引函数,我假设它在根目录内,所以我尝试了几个 url 的
http://localhost/basketball-app-framework/public/players
http://localhost/basketball-app-framework/players
这最后一个显然只有在我将 localhost 指向公共目录时才有效,但我确实这样做了,但仍然不行。我还是一头雾水。
http://localhost/players
我尝试了一堆其他的网址,但只有那些是有意义的,而且我很确定应该可以工作。
我必须做一些挖掘才能弄清楚我肯定犯了这个简单的错误,但无论如何我都无法理解为什么我无法从我的数据库中获取该数据。
【问题讨论】: