使用以下代码,我收到MethodNotAllowedHttpException
错误。该代码适用于简单的博客文章。当我点击以下链接时,我收到错误。
HTML::link('admin/createpost', 'Add Post')
我找不到代码有什么问题。请帮帮我。感谢
Route.php:
<?php
Route::get('/', 'HomeController@getIndex');
Route::get('login', 'HomeController@getLogin');
Route::post('login', 'HomeController@postLogin');
Route::get('logout', 'HomeController@logout');
Route::get('users', 'HomeController@showusers');
Route::group(array('before' => 'auth'), function(){
Route::get('admin', 'AdminController@getIndex');
Route::get('admin/createpost', array('as'=>'createpost' ,'uses'=>'AdminController@getCreate'));
Route::post('admin/createpost', array('as'=>'createpost','uses'=>'AdminController@postCreate'));
});
AdminConroller:
<?php
class AdminController extends \BaseController {
protected $table ='posts';
protected $post;
public function getIndex()
{
return View::make('admin.index');
}
public function getCreate()
{
return View::make('admin.createpost');
}
public function postCreate()
{
// Declare the rules for the form validation
$rules = array(
'title' => 'required|min:3',
'content' => 'required|min:3'
);
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes())
{
// Create a new blog post
$user = Auth::user();
$post = new Post();
// Update the blog post data
$post->title = Input::get('title');
$post->content = Input::get('content');
$post->username = $user->username;
// Was the blog post created?
if($post->save())
{
// Redirect to the new blog post page
return Redirect::to('admin/createpost');
}
// Redirect to the blog post create page
return Redirect::to('admin/createpost');
}
return View::make('admin.createpost')->withInput()->withErrors($validator);
}
}
答案 0 :(得分:0)
我无法测试这个 - 但我认为这是因为你不能使用相同的链接和相同的名称,除非你使用命名路由。
尝试将路线名称更改为正常的宁静标准
Route::get('admin/createpost', array('as'=>'createpost' ,'uses'=>'AdminController@getCreate'));
Route::post('admin', array('as'=>'storepost','uses'=>'AdminController@postCreate'));
然后用这个
链接到它HTML::linkRoute('admin.createpost', 'Add Post')