本文整理汇总了PHP中app\Post::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::validate方法的具体用法?PHP Post::validate怎么用?PHP Post::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postCreate
/**
* admin create new post
* @author Tran Van Moi
* @since 2015/06/03
* @return response
*/
public function postCreate()
{
$data = Input::all();
$validator = Post::validate($data);
if ($validator->fails()) {
return Redirect::to('post/create')->withInput()->withErrors($validator);
} else {
$post = Post::create_post($data);
if (count($post)) {
return redirect('admin/post/create')->withInput()->with('create_status', ['status' => 'success', 'message' => 'Create a new post is success!']);
} else {
return redirect('admin/post/create')->withInput()->with('create_status', ['status' => 'danger', 'message' => 'Create a new post is failed! Please try again!']);
}
}
}
示例2: postEdit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function postEdit($post_id = null)
{
$check_delete_post = Post::whereDelete_status(0)->whereId($post_id)->first();
if ($check_delete_post) {
$data = Input::all();
$validator = Post::validate($data);
if ($validator->fails()) {
return Redirect::to('post/edit/' . $post_id)->withInput()->withErrors($validator);
} else {
$check_delete_post->title = $data['title'];
$check_delete_post->content = $data['content'];
$check_delete_post->category_id = $data['category'];
if (Input::file('image')) {
$destination_path = './public/images/post/';
// upload path
$extension = Input::file('image')->getClientOriginalExtension();
// getting image extension
$file_name = str_random(8) . '.' . $extension;
// renameing image
if (Input::file('image')->move($destination_path, $file_name)) {
if ($check_delete_post->image != "" && File::exists($destination_path . $check_delete_post->image)) {
File::delete($destination_path . $check_delete_post->image);
}
$check_delete_post->image = $file_name;
}
}
$check_delete_post->save();
Session::flash('post_status', ['status' => 'success', 'message' => 'Edit post is success!']);
return redirect()->back();
}
} else {
return redirect('post/edit');
}
}