Laravel 方法在post上不允许HttpException
现在我学习建立一个类似facebook的网站。昨天,我可以发布“状态”,但经过一些修改后,状态发布不起作用 当我点击提交按钮时 它抛出MethodNotAllowedHttpException 如何解决这个问题? 尝试了一些方法,但得到了相同的结果 表格:Laravel 方法在post上不允许HttpException,laravel,laravel-routing,Laravel,Laravel Routing,现在我学习建立一个类似facebook的网站。昨天,我可以发布“状态”,但经过一些修改后,状态发布不起作用 当我点击提交按钮时 它抛出MethodNotAllowedHttpException 如何解决这个问题? 尝试了一些方法,但得到了相同的结果 表格: {{Form::open(array('url'=> 'postStatus','files'=>'true'))}} {{Form::textarea('status')}} {{Form::file('picture')
{{Form::open(array('url'=> 'postStatus','files'=>'true'))}}
{{Form::textarea('status')}}
{{Form::file('picture')}}
{{Form::submit('Post')}}
{{Form::close()}}
路线:
Route::get('/', function()
{
if(Auth::check()){
$post = Newsfeed::all();
return View::make('frontend/home/index')->with('posts', $post->reverse());
}
$months = [];
foreach (range(1, 12) as $month) {
$months[$month] = substr(strftime("%B", mktime(0, 0, 0, $month)), 0, 3);
}
$months = [''=>'Month'] + $months;
return View::make('frontend/register/index')->with('months', $months);
});
Route::post('login', 'LoginController@validateLogin');
Route::get('logout', 'LoginController@doLogout');
Route::post('register', 'LoginController@validateRegister');
Route::post('upload', 'ProfileController@changePP');
Route::get('{username}', 'ProfileController@show');
Route::post('postStatus', 'HomeController@postStatus');
Route::get('deleteStatus/{postid}', 'HomeController@deleteStatus');
Route::get('unlike/{likeid}', 'HomeController@unlike');
Route::get('like/{postid}', 'HomeController@like');
Route::post('comment/{postid}', 'HomeController@postComment');
Route::get('deleteComment/{commentid}', 'HomeController@deleteComment');
家庭控制器
public function postStatus()
{
try{
$status = Input::get('status');
$file = Input::file('picture');
if($file !== '' || $status !=''){
$post = new Newsfeed;
$post->userid = Auth::id();
if($status !=''){
$post->status = $status;
}
if($file != ''){
$rules = array('file' => 'mimes:png,jpg,jpeg');
$validator = Validator::make(array('file'=> $file), $rules);
if($validator->passes()){
$destinationPath = 'images/upload';
$filename = $file->getClientOriginalName();
$file->move('public/'.$destinationPath, $filename);
$post->image = $destinationPath.'/'.$filename;
}
}
$post->save();
}
return Redirect::to('');
}catch(Exception $e){
return Redirect::to('');
}
}
public function show($fullname)
{
$temp = explode('.',$fullname);
$owner = User::where('firstname', '=', $temp[0])->where('lastname', '=', $temp[1])->first();
if($owner){
return View::make('frontend/profile/index')->with('owner', $owner);
}
return View::make('frontend/profile/notfound');
}
轮廓控制器
public function postStatus()
{
try{
$status = Input::get('status');
$file = Input::file('picture');
if($file !== '' || $status !=''){
$post = new Newsfeed;
$post->userid = Auth::id();
if($status !=''){
$post->status = $status;
}
if($file != ''){
$rules = array('file' => 'mimes:png,jpg,jpeg');
$validator = Validator::make(array('file'=> $file), $rules);
if($validator->passes()){
$destinationPath = 'images/upload';
$filename = $file->getClientOriginalName();
$file->move('public/'.$destinationPath, $filename);
$post->image = $destinationPath.'/'.$filename;
}
}
$post->save();
}
return Redirect::to('');
}catch(Exception $e){
return Redirect::to('');
}
}
public function show($fullname)
{
$temp = explode('.',$fullname);
$owner = User::where('firstname', '=', $temp[0])->where('lastname', '=', $temp[1])->first();
if($owner){
return View::make('frontend/profile/index')->with('owner', $owner);
}
return View::make('frontend/profile/notfound');
}
您需要做的是移动路由::获取“{username}”ProfileController@show'; 这是最后一条路线 发生的情况是,您的postStatus被作为用户名进行了中断,并且失败了 我个人会把你的用户名改成这样
Route::get('/user/{username}', 'ProfileController@show');
否则,在表单::open中添加'method'=>'POST'时,这种类型的catchall将出现奇怪的错误
请参阅,如果这解决了您的问题。我可以更改postStatus的路由而不是更改用户的路由吗?因为我想直接使用url访问配置文件,postStatus只是临时编辑:我更改了用户名路由,但如果您的用户名路由是路由文件中的最后一个路由,则得到相同的结果,但我现在告诉您-这将导致问题。如果您的用户名是上载、登录或其他内容,它将与您的其他路由冲突。我已经进入最后一行,更改用户名路由,更改postStatus路由,所有这些都不起作用。@VensonWijaya请尝试composer dumpautoload。我知道这没什么用,但还是试试看吧。