當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。