现在我学会建立一个类似网络的脸书。昨天,我可以发布状态'但经过一些修改后,状态发布无效
当我点击提交按钮 它抛出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', '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');
的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 :(得分:0)
您需要做的是将Route::get('{username}', 'ProfileController@show');
移至最后一条路线。
正在发生的事情是您的postStatus
已被截取为用户名,并且失败了。
就个人而言,我会将您的用户名路由更改为
Route::get('/user/{username}', 'ProfileController@show');
否则你会因为这种类型的捕获而出现奇怪的错误
答案 1 :(得分:0)
在Form::open
中添加'方法' =>' POST' 。
看,如果能解决你的问题。