0
다음 코드를 사용하면 MethodNotAllowedHttpException
오류가 발생합니다. 이 코드는 간단한 블로그 게시물을위한 것입니다. 다음 링크를 클릭하면 오류가 발생합니다.MethodNotAllowedHttpException 오류
HTML::link('admin/createpost', 'Add Post')
코드에 무엇이 잘못되었는지를 알 수 없습니다. 제발 도와주세요. 감사합니다
Route.php는 :
<?php
Route::get('/', '[email protected]');
Route::get('login', '[email protected]');
Route::post('login', '[email protected]');
Route::get('logout', '[email protected]');
Route::get('users', '[email protected]');
Route::group(array('before' => 'auth'), function(){
Route::get('admin', '[email protected]');
Route::get('admin/createpost', array('as'=>'createpost' ,'uses'=>'[email protected]'));
Route::post('admin/createpost', array('as'=>'createpost','uses'=>'[email protected]'));
});
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);
}
}
감사와 링크. Route :: post ('admin/createpost', array ('createpost', 'uses'=> 'AdminController @ getCreate')) admin/createpost ','AdminController @ postCreate ');' 오류없이 정상적으로 작동합니다. 게시물 경로에 대한 샘플 코드에서 명명 된 라우팅이 사용되지 않았 음을 관찰했습니다. 반드시 준수해야합니까? – kishan
나는 그것을 엄격히 따른다. 응용 프로그램이 성장함에 따라 원하는 대상을 정확하게 지정하는 것이 더욱 강력한 라우팅이됩니다. 그리고 나는 명명 된 경로를 사용할 때 오류와 이상한 라우팅 문제 (이 경우와 같은)를 덜받는 경향이 있습니다. – Laurence
laravel이 post route로 가정하는 방법은 링크가 다르면 경로를 가져 오는 것과 같습니다. 경로 이름이 달라야 함을 의미합니까? – kishan