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


PHP Post::findOrFail方法代码示例

本文整理汇总了PHP中Post::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::findOrFail方法的具体用法?PHP Post::findOrFail怎么用?PHP Post::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Post的用法示例。


在下文中一共展示了Post::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: posts

 public function posts($id)
 {
     $this->load->helper('form');
     $this->load->model(['post', 'comment']);
     $post = NULL;
     try {
         $post = Post::findOrFail($id);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         show_404();
     }
     $data = ['menu' => 'blog', 'post' => $post];
     $this->load->library('form_validation');
     $this->form_validation->set_error_delimiters('<p class="text-danger"><strong><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ', '</strong></p>');
     if ($this->form_validation->run('create-comment') == FALSE) {
         $this->load->view('front/blog-post', $data);
     } else {
         $comment = new Comment();
         $comment->post_id = $this->input->post('id');
         $comment->name = $this->input->post('name');
         $comment->content = $this->input->post('comment');
         $comment->save();
         $this->session->set_flashdata('message', 'Successfully save!');
         redirect('posts/' . $id . '#comments');
     }
 }
开发者ID:harithaakella,项目名称:CS597-Project-Code,代码行数:25,代码来源:Welcome.php

示例2: postComment

 public function postComment($id)
 {
     $input = Input::all();
     Log::info($input);
     $validator = Comment::validate($input);
     if ($validator->fails()) {
         FlashHelper::message("Null title", FlashHelper::DANGER);
         return;
     }
     $post = Post::findOrFail($id);
     if (!$post->can_comment || !PrivacyHelper::checkPermission(Auth::user(), $post)) {
         throw new Exception("Don't have permision");
     }
     $comment = new Comment();
     $Parsedown = new Parsedown();
     $comment->post_id = $id;
     $comment->parrent_id = $input['parrent_id'];
     $comment->markdown = $input['markdown'];
     Log::info($comment);
     $comment->HTML = $Parsedown->text($comment->markdown);
     $comment->save();
     $comment->comments = array();
     $data['html'] = View::make('posts._comment')->with('data', $comment)->with('level', count($comment->parents()))->with('can_comment', true)->render();
     $data['status'] = true;
     $data['parent_id'] = $comment->parrent_id;
     return Response::json($data);
 }
开发者ID:sh1nu11bi,项目名称:CloMa,代码行数:27,代码来源:CommentController.php

示例3: destroy

 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $this->authorOrAdminPermissioinRequire($post->user_id);
     Post::destroy($id);
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('posts.index');
 }
开发者ID:Kouga-Huang,项目名称:laravel-blog,代码行数:8,代码来源:PostsController.php

示例4: update

 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $post->update($data);
     return Redirect::route('admin.posts.index');
 }
开发者ID:mldarshana,项目名称:Getting-started-with-Laravel-4,代码行数:16,代码来源:AdminPostsController.php

示例5: fieldsFromModel

 /**
  * Return the field values from the model
  *
  * @param integer $id
  * @param array $fields
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $post = Post::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $post->{$field};
     }
     $fields['tags'] = $post->tags()->lists('tag')->all();
     return $fields;
 }
开发者ID:wedojava,项目名称:hfblogstudy.dev,代码行数:18,代码来源:PostFormFields.php

示例6: accept_a_post

 public function accept_a_post($id)
 {
     if (!Auth::check() || !Auth::user()->isAdmin()) {
         return Redirect::route('login');
     } else {
         $postReference = Post::findOrFail($id);
         $postReference->moderated = true;
         $postReference->save();
         return Redirect::route('admin_panel');
     }
 }
开发者ID:jtaurus,项目名称:jtauri_blog,代码行数:11,代码来源:AdminController.php

示例7: update

 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $slug = str_replace(' ', '-', Input::get('title'));
     $data['slug'] = $slug;
     $post->update($data);
     return Redirect::route('admin.posts.list');
 }
开发者ID:syafdia,项目名称:PAS,代码行数:18,代码来源:AdminPostsController.php

示例8: applyVote

 public function applyVote($user, $type, $type_id, $updown)
 {
     //deal with item table
     $item = "";
     switch ($type) {
         case Constant::POST_TYPE:
             $item = Post::findOrFail($type_id);
             break;
         case Constant::COMMENT_TYPE:
             $item = Comment::findOrFail($type_id);
             Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $item->post_id);
             break;
         case Constant::SECTION_TYPE:
             $item = Section::findOrFail($type_id);
             break;
         default:
             throw new UnexpectedValueException("type: {$type} not enumerated");
     }
     //increment our total vote counter
     $user->increment('votes');
     //decrement one point for voting
     $user->decrement('points');
     //double decrement for self upvote
     if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
         if ($item->user_id == Auth::user()->id && $updown == Constant::VOTE_UP) {
             $user->decrement('points');
         }
     }
     //upvote/downvote the item itself
     if ($updown == Constant::VOTE_UP) {
         $item->increment('upvotes');
     } else {
         if ($updown == Constant::VOTE_DOWN) {
             $item->increment('downvotes');
         }
     }
     //upvote/downvote user who posted (ignore for sections)
     if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
         $rec_user = User::findOrFail($item->user_id);
         if ($updown == Constant::VOTE_UP) {
             $rec_user->increment('points');
         } else {
             if ($updown == Constant::VOTE_DOWN) {
                 $rec_user->decrement('points');
             }
         }
     }
     //deal with votes table
     $vote = new Vote(array('type' => $type, 'user_id' => Auth::user()->id, 'item_id' => $type_id, 'updown' => $updown));
     $vote->save();
 }
开发者ID:hrenos,项目名称:spreadit,代码行数:51,代码来源:Vote.php

示例9: make

 public function make($post_id, $content, $parent_id)
 {
     $block = new SuccessBlock();
     $block->data->comment_id = -1;
     if ($block->success) {
         if (Auth::user()->points < 1) {
             $block->success = false;
             $block->errors[] = 'You need at least one point to post a comment';
         }
     }
     if ($block->success) {
         if (!$this->canPost()) {
             $block->success = false;
             $block->errors[] = 'can only post ' . Utility::availableComments() . ' per day';
         }
     }
     if ($block->success) {
         $data = ['data' => Markdown::defaultTransform(e($content)), 'parent_id' => $parent_id, 'user_id' => Auth::user()->id, 'post_id' => $post_id, 'markdown' => $content];
         $rules = array('user_id' => 'required|numeric', 'parent_id' => 'required|numeric', 'post_id' => 'required|numeric', 'markdown' => 'required|max:' . Constant::COMMENT_MAX_MARKDOWN_LENGTH);
         $validate = Validator::make($data, $rules);
         if ($validate->fails()) {
             $block->success = false;
             foreach ($validate->messages()->all() as $v) {
                 $block->errors[] = $v;
             }
         }
     }
     if ($block->success) {
         $post = Post::findOrFail($data['post_id']);
         $notification = new Notification();
         if ($data['parent_id'] != Constant::COMMENT_NO_PARENT) {
             $parent = $this->findOrFail($data['parent_id']);
             $notification->type = Constant::NOTIFICATION_COMMENT_TYPE;
             $notification->user_id = $parent->user_id;
         } else {
             $notification->type = Constant::NOTIFICATION_POST_TYPE;
             $notification->user_id = $post->user_id;
         }
         $comment = new Comment($data);
         $comment->save();
         $post->increment('comment_count');
         $notification->item_id = $comment->id;
         $block->data->comment_id = $comment->id;
         if ($notification->user_id != Auth::user()->id) {
             $notification->save();
         }
         Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $post_id);
     }
     return $block;
 }
开发者ID:hrenos,项目名称:spreadit,代码行数:50,代码来源:Comment.php

示例10: applyTag

 public function applyTag($post_id, $type, $updown)
 {
     $post = Post::findOrFail($post_id);
     //upvote/downvote the post itself
     if ($updown == Constant::TAG_UP) {
         $post->increment($this->getColumn($type));
     } else {
         if ($updown == Constant::TAG_DOWN) {
             $post->decrement($this->getColumn($type));
         }
     }
     //deal with votes table
     $tag = new Tag(array('type' => $type, 'user_id' => Auth::user()->id, 'post_id' => $post_id, 'updown' => $updown));
     $tag->save();
 }
开发者ID:hrenos,项目名称:spreadit,代码行数:15,代码来源:Tag.php

示例11: update

 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update()
 {
     $data = Input::all();
     $id = $data['id'];
     $post = Post::findOrFail($id);
     $validator = Validator::make($data, Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if (empty($data['image'])) {
         unset($data['image']);
     } else {
         $data['image'] = ImageHandler::uploadImage($data['image'], 'images');
     }
     $post->update($data);
     return Redirect::to('admin/posts/edit' . '/' . $id)->with(array('note' => 'Successfully Updated Post!', 'note_type' => 'success'));
 }
开发者ID:rinodung,项目名称:hello-video-laravel,代码行数:23,代码来源:AdminPostController.php

示例12: setPublish

 public function setPublish($id)
 {
     $post = \Post::findOrFail($id);
     //Conseguimos el canal puesto como principal
     if ($post->status == 1) {
         return Redirect::back()->with('error', 'Ya ha sido publicado con exito anteriormente');
     }
     $channel = Helper::getChannel($post->channel_id);
     $data = array('name' => $post->title, 'link' => $post->link, 'description' => strip_tags(HTML::decode($post->text)), 'picture' => $post->img);
     $res = $channel->Publish($data);
     if (!$res['status']) {
         $post->status = 5;
         $post->result_post = $res['error'];
         $post->save();
         return Redirect::back()->with('error', $res['error']);
     } else {
         $post->status = 1;
         $post->result_post = $res['status'];
         $post->channel_id = $channel->id;
         $post->save();
         return Redirect::back()->with('message', 'Publicado con éxito');
     }
     // die($post->result_status);
 }
开发者ID:jsehersan,项目名称:social,代码行数:24,代码来源:PublicationsController.php

示例13: edit

 public function edit($id)
 {
     $post = Post::findOrFail($id);
     return Response::json(array('error' => false, 'posts' => $post));
 }
开发者ID:nnil4cl,项目名称:blog,代码行数:5,代码来源:PostController.php

示例14: update

 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $file = Input::file('image');
     $category = Postcategory::find(Input::get('post_category_id'));
     $data = array('title' => ucwords(Input::get('title')), 'slug' => $this->slugify(Input::get('slug')), 'content' => Input::get('content'), 'excerpt' => Input::get('excerpt'), 'post_category_id' => Input::get('post_category_id'), 'status' => Input::get('status'), 'comment_status' => Input::get('comment_status'), 'social_status' => Input::get('social_status'), 'created_at' => Input::get('created_at'));
     $validator = Validator::make($data, Post::rules($id));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if (Input::hasFile('image')) {
         // checking file is valid.
         if (Input::file('image')->isValid()) {
             $destinationPath = '/uploads/' . $category->slug;
             // upload path
             $extension = Input::file('image')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(1, 1000) . '_' . $data['slug'] . '.' . $extension;
             // renameing image
             Input::file('image')->move(public_path() . $destinationPath, $fileName);
             // uploading file to given path
             $data['image'] = $destinationPath . "/" . $fileName;
         } else {
             // sending back with error message.
             return Redirect::back()->with('errors', 'Uploaded file is not valid')->withInput();
         }
     }
     if (Input::hasFile('documents')) {
         $documents = Input::file('documents');
         foreach ($documents as $newdocument) {
             if ($newdocument !== NULL) {
                 // dd($newdocument);
                 // checking file is valid.
                 $destinationPath = '/uploads/documents';
                 // upload path
                 $fileName = rand(1, 1000) . '_' . $newdocument->getClientOriginalName();
                 // renameing image
                 $newdocument->move(public_path() . $destinationPath, $fileName);
                 // uploading file to given path
                 // Save the photo
                 $document = new Document();
                 $document->name = $fileName;
                 $document->path = $destinationPath . "/" . $fileName;
                 $document->save();
                 $post->documents()->save($document);
             }
         }
     }
     if (Input::has('related_members')) {
         $post->members()->sync(Input::get('related_members'));
     }
     $post->update($data);
     return Redirect::route('admin.posts.edit', $post->id)->with("message", "Data berhasil disimpan");
 }
开发者ID:arbuuuud,项目名称:gnt-aops,代码行数:60,代码来源:PostsController.php

示例15: update

 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // We remove quotes from tag_ids with array_map intval
     $tag_ids = array_map('intval', $data['tags']);
     $post->update(['title' => $data['title'], 'content' => $data['content'], 'status' => $data['status']]);
     $post->categories()->sync([$data['category']]);
     $post->tags()->sync($tag_ids);
     return Redirect::route('posts.show', $id)->withInfo(Lang::get('larabase.post_updated'));
 }
开发者ID:pogliozzy,项目名称:larabase,代码行数:14,代码来源:PostsController.php


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