我目前正在试图在索引页上创建一个允许用户创建项目的链接。我routes.php文件看起来像无法生成URL
Route::controller('items', 'ItemController');
和我ItemController看起来像
class ItemController extends BaseController
{
// create variable
protected $item;
// create constructor
public function __construct(Item $item)
{
$this->item = $item;
}
public function getIndex()
{
// return all the items
$items = $this->item->all();
return View::make('items.index', compact('items'));
}
public function getCreate()
{
return View::make('items.create');
}
public function postStore()
{
$input = Input::all();
// checks the input with the validator rules from the Item model
$v = Validator::make($input, Item::$rules);
if ($v->passes())
{
$this->items->create($input);
return Redirect::route('items.index');
}
return Redirect::route('items.create');
}
}
我曾试图改变getIndex()只指数(),但然后我得到找不到控制器的方法。所以,这就是我使用getIndex()的原因。
我想我已正确设置我的创建控制器,但是当我去的项目/创建网址我得到一个
无法生成用于命名路线“items.store”这样路线的网址不存在。
错误。我试过使用store()和getStore()而不是postStore(),但我一直得到相同的错误。
有人知道问题可能是什么?我不明白为什么网址没有被生成。
** + 1用于发布_broad代码sample_与您的问题!** –