2016-08-01 62 views
0

我正在像一個社交媒體應用程序......但在我的控制器最後其他人,如果不工作狀態上傳。但文件和視頻uload很好地工作。這是什麼正確的格式。 這裏是我的控制器Laravel控制器不工作狀態不起作用

public function getclass(Request $request) 
{ 


    if (Input::has('post_comment')) 
    { 
     $status=Input::get('post_comment'); 
     $commentBox=Input::get('comment_text'); 
     $selectedStatus=Status::find($status); 

     $selectedStatus->comments()->create([ 
      'comment_text'=>$commentBox, 
      'user_id'=>Auth::user()->id, 
      'status_id'=>$status 

      ]); 
     Flash::message('Your comments has been posted'); 
     return redirect(route('class')); 
    } 

    if(Input::has('status-text')) 
    { 
     $text=e(Input::get('status-text')); 
     $rules = [ 
      'status_text'=>'required|string', 
     ]; 
     $validator = Validator::make($request->all(), $rules); 


     if(Input::hasFile('status_image_upload')) 
     { 
      $rules['status_image_upload'] = 'image'; 
      $validator = Validator::make($request->all(), $rules); 
      if($validator->fails()) 
      { 
       $image = $request->file('status_image_upload'); 
       $imageName = str_random(8).'_'.$image->getClientOriginalName(); 
       $image->move('status_images', $imageName); 
       $userStatus = new Status(); 
       $userStatus -> status_text = $text; 
       $userStatus -> image_url = $imageName; 
       $userStatus -> type = 1; 
       $userStatus -> users_id = Auth::user()->id; 
       $userStatus -> save(); 

       Flash::success('Your status has been posted'); 
       return redirect(route('class')); 
      } 
     } 
     else if ($validator->fails()) 
     { 
      $userStatus = new Status(); 
      $userStatus -> status_text = $text; 
      $userStatus -> video_url = $request['video_url']; 
      $userStatus -> type = 2; 
      $userStatus -> users_id = Auth::user()->id; 
      $userStatus -> save(); 

      Flash::success('Your status has been posted'); 
      return redirect(route('class')); 
     } 
     else if($validator->fails()) 
     { 
      $userStatus = new Status(); 
      $userStatus -> status_text = $text; 
      $userStatus -> type = 3; 
      $userStatus -> users_id = Auth::user()->id; 
      $userStatus -> save(); 

      Flash::success('Your status has been posted'); 
      return redirect(route('class')); 
     } 
    } 


     return view('class',[ 
     'posts'=>status::orderBy('id','DESC')->get() 
     ]); 
} 

在這個控制器 這個代碼不工作

else if($validator->fails()) 
    { 
     $userStatus = new Status(); 
     $userStatus -> status_text = $text; 
     $userStatus -> type = 3; 
     $userStatus -> users_id = Auth::user()->id; 
     $userStatus -> save(); 

     Flash::success('Your status has been posted'); 
     return redirect(route('class')); 
    } 

回答

0

我注意到,你有兩個

else if($validator->fails()) { 

} 

是否用$ validator->失敗()返回一個BOOL?你能證實嗎?

+0

else {user_id = new Status(); $ userStatus - > status_text = $ text; $ userStatus - > type = 3; $ userStatus - > users_id = Auth :: user() - > id; $ userStatus - > save(); Flash :: success('您的狀態已發佈'); return redirect(route('class')); }如果我給這樣的話,它也不能正常工作...請你給我正確的格式.. – Shuvo

+0

你能迴應結果$ validator-> failed()嗎? – Ronald

+0

不,先生...我認爲它不需要...我使用這個因爲如果我使用其他,如果然後必須要條件多數民衆贊成爲什麼我使用它。 – Shuvo