i working social media application... in controller last else if not working status upload. file , video uload working nicely. correct format this. here controller
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() ]);
}
in controller code not working
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')); }
that portion of code never executed. because else if
block above code i.e part
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')); }
has kind of block it. using same condition in both else if
block. means if above else if
condition fails other fail. , validation rules
using in both conditions same.
Comments
Post a Comment