我的工作方式与社交媒体应用程序相似......但如果不在状态上传工作,请在我的控制器中使用。但文件和视频uload工作得很好。什么是正确的格式。 这是我的控制器
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 :(得分:0)
我注意到你有两个
else if($validator->fails()) {
}
$ validator-> failed()是否返回BOOL?你能核实一下吗?