2015-02-10 85 views
0

现在我学会建立一个像Facebook一样的Facebook。昨天,我可以发布状态,但一些修改后,状态发布简化版,工作MethodNotAllowedHttpException在岗位

当我点击提交按钮 扔MethodNotAllowedHttpException

如何解决这一问题? 尝试一些方法,但得到同样的结果

形式:

{{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', '[email protected]'); 
Route::get('logout', '[email protected]'); 
Route::post('register', '[email protected]'); 

Route::post('upload', '[email protected]'); 
Route::get('{username}', '[email protected]'); 

Route::post('postStatus', '[email protected]'); 
Route::get('deleteStatus/{postid}', '[email protected]'); 
Route::get('unlike/{likeid}', '[email protected]'); 
Route::get('like/{postid}', '[email protected]'); 
Route::post('comment/{postid}', '[email protected]'); 
Route::get('deleteComment/{commentid}', '[email protected]'); 

的HomeController

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(''); 
    } 
} 

ProfileController可

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'); 
    } 

回答

0

您需要做的是将Route::get('{username}', '[email protected]');作为最后一条路线。

发生了什么事是你的postStatus被作为用户名被拦截,并失败。

个人而言,我会改变你的用户名的路线是这样的

Route::get('/user/{username}', '[email protected]'); 

否则你会得到奇怪的错误,这种类型包罗万象

+0

而不是改变用户的路线,我可以改变postStatus的路线?因为我想直接访问配置文件的URL和postStatus只是临时编辑:我改变了用户名路线,但得到了相同的结果 – 2015-02-10 05:54:54

+0

只有当你的'用户名'路线是非常非常最后一个路线在您的路线文件 – Laurence 2015-02-10 05:59:12

+0

但我现在告诉你 - 这会导致问题。如果你的用户名是'upload'或'login'什么的 - 它会和你的其他路线发生冲突。 – Laurence 2015-02-10 05:59:41

0

添加“方法” =>“POST”在你的Form::open

请参阅,如果这可以解决您的问题。

+0

。相同的结果 – 2015-02-10 05:59:08

+0

POST是默认的,如果没有指定... – lukasgeiter 2015-02-10 07:35:10

+0

@VensonWijaya尝试作曲家dumpautoload。我知道它不会帮助,但只是试试看。 – 2015-02-10 07:37:03