当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::validate方法代码示例

本文整理汇总了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!']);
         }
     }
 }
开发者ID:ambarsetyawan,项目名称:laravel-1,代码行数:21,代码来源:PostController.php

示例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');
     }
 }
开发者ID:ambarsetyawan,项目名称:laravel-1,代码行数:40,代码来源:PostController.php


注:本文中的app\Post::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。