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


PHP Post::find方法代码示例

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


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

示例1: store

 public function store()
 {
     $id = $this->request->input('id');
     $input = $this->request->only(['provider', 'text', 'link', 'image']);
     $categories = $this->request->input('categories');
     $inputSchedule = $this->request->only(['schedule_date', 'schedule_time']);
     if ($input['provider'] == 'weblink' && !$input['link']) {
         throw new Exception('The "link" argument is missing', 1);
     }
     $post = (int) $id ? Post::find($id)->fill($input) : new Post($input);
     if ($inputSchedule['schedule_date']) {
         $time = explode(':', $inputSchedule['schedule_time']);
         $date = new Carbon($inputSchedule['schedule_date']);
         if (count($time) > 1) {
             $date->setTime($time[0], $time[1]);
         }
         if ($date->timestamp > time()) {
             $post->posted_at = $date;
         }
     } else {
         $post->posted_at = new Carbon();
     }
     $post->user_id = $this->auth->id();
     $post->save();
     if (count($categories)) {
         $post->categories()->sync($categories);
     } else {
         $post->categories()->detach();
     }
     $post->provider_id = $post->id;
     $success = $post->save();
     $job = (new PublishPost($post))->onQueue('publish');
     $queued = $this->dispatch($job);
     return compact('success', 'queued');
 }
开发者ID:net-shell,项目名称:socialsync,代码行数:35,代码来源:PostController.php

示例2: post

 function post($id)
 {
     $data['post'] = Post::find($id);
     $data['comments'] = Comment::where('post_id', '=', $id)->with('user')->get();
     //$data['comments'] = Comment::find($id);
     return view('blog/post', $data);
 }
开发者ID:rahulrockers,项目名称:laravel-demo,代码行数:7,代码来源:UserController.php

示例3: doUpdate

 public function doUpdate($id, $request)
 {
     DB::transaction(function () use($id, $request) {
         $post = Post::find($id);
         $post->title = $request->input('title');
         $post->content = $request->input('content');
         $post->allow_comments = $request->input('allow_comments') !== null ? 1 : null;
         if ($request->input('status') !== null && $request->input('status') == 'published') {
             $post->status = 'published';
             if ($request->input('published_at') !== null) {
                 $post->published_at = new \DateTime($request->input('published_at'));
             } else {
                 $post->published_at = new \DateTime();
             }
         } else {
             $post->status = 'draft';
             $post->published_at = null;
         }
         $post->save();
         $post->slug = $this->makeSlug($post);
         $post->setCategories($post, $request->input('category_id'), $request->input('new_category'));
         $post->setTags($post, commaListToArray($request->input('tags')));
         //\File::cleanDirectory(app('http_cache.cache_dir'));
     });
 }
开发者ID:ambarsetyawan,项目名称:brewski,代码行数:25,代码来源:Post.php

示例4: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request)
 {
     $post = Post::find($request->post_id);
     $topic = $post->topic_id;
     $post->delete();
     return Redirect::action('TopicController@show', array('id' => $topic));
 }
开发者ID:prudywsh,项目名称:tpe,代码行数:13,代码来源:PostController.php

示例5: destroy

 /**
  * Destroy the given post.
  *
  * @param  Request  $request
  * @param  string  $postId
  * @return Response
  */
 public function destroy(Request $request, $postId)
 {
     $post = Post::find($postId);
     $this->authorize('destroy', $post);
     $post->destroy($postId);
     return redirect('/posts');
 }
开发者ID:vaiveg,项目名称:vaiva-blog,代码行数:14,代码来源:PostController.php

示例6: adminEditPost

 public function adminEditPost(Request $request)
 {
     $post = Post::find($request->id);
     $post->content = $request->content;
     $post->save();
     return back();
 }
开发者ID:Ristop,项目名称:valgeranna,代码行数:7,代码来源:AdminController.php

示例7: store

 /**
  *  信件楼
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (!Auth::check()) {
         return response()->json(['errno' => 2, 'msg' => 'require authentication']);
     }
     $pid = $request->input('pid');
     $content = $request->input('content');
     if (!$pid || !$content) {
         return response()->json(['errno' => 1, 'msg' => 'require pid and content']);
     }
     $post = Post::find($pid);
     if (!$post) {
         return response()->json(['errno' => 3, 'msg' => 'post not found']);
     }
     $floor = new Floor();
     $floor->pid = $pid;
     $floor->uid = Auth::user()->id;
     $floor->content = $content;
     $floor->pics = $request->input('pics');
     $floor->at_users = $request->input('at_users');
     $floor->save();
     //更新时间戳
     $floor->post->touch();
     return response()->json(['errno' => 0, 'msg' => 'success', 'floor' => $floor]);
 }
开发者ID:BLUESTC,项目名称:SeTieba_BE_PHP,代码行数:31,代码来源:FloorController.php

示例8: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $like = Like::find($id);
     $post = Post::find($like->post_id);
     Like::destroy($id);
     return redirect('users');
 }
开发者ID:BQuiroga,项目名称:finalSis,代码行数:13,代码来源:LikesController.php

示例9: newPost

 public function newPost(Request $request)
 {
     $post = $request->has('temp_id') ? Post::find($request->only(['temp_id'])) : null;
     $title = is_null($post) ? null : $post->title;
     $body = is_null($post) ? null : $post->body;
     return view('admin.posts.new', compact('post', 'title', 'body'));
 }
开发者ID:andycrockett,项目名称:andycrockett,代码行数:7,代码来源:AdminController.php

示例10: getAction

 public function getAction($post = null, $action = null)
 {
     $post = Post::find($post);
     if (!$post) {
         app()->abort(422);
     }
     if ($action) {
         // Log action and push to queue
         $log = Log::firstOrNew(['reason' => $action, 'market_item_id' => $post->market()->whereAction($action)->first()->id]);
         if (!$log->id) {
             Auth::user()->log()->save($log);
             $job = (new AwaitAction($log))->onQueue('check');
             $this->dispatch($job);
         } else {
             return ['error' => trans('app.action_duplicate')];
         }
     }
     if (!$post) {
         return ['success' => true];
     }
     $url = !$action ? false : $this->social->with($post->provider)->action($action, $post->provider_id);
     if ($url === true) {
         return ['success' => true];
     }
     if (!$url || !parse_url($url)) {
         $url = $post->link;
     }
     return ['success' => true, 'redirect' => $url];
 }
开发者ID:net-shell,项目名称:socialsync,代码行数:29,代码来源:SiteController.php

示例11: show

 public function show($id)
 {
     $post = Post::find($id);
     $comments = $post->comments;
     // return $comments;
     return view("posts/show")->with(['post' => $post, 'comments' => $comments]);
 }
开发者ID:erzhu4,项目名称:larvelProject,代码行数:7,代码来源:PostsController.php

示例12: comment

 public function comment($id, Request $request)
 {
     $post = \App\Post::find($id);
     $comment = \App\Comment::create($request->all());
     $post->comments()->save($comment);
     return redirect()->route('posts.show', $post->id);
 }
开发者ID:hsaung,项目名称:formrequest,代码行数:7,代码来源:PostsController.php

示例13: boot

 /**
  * Register any application authentication / authorization services.
  *
  * @param  \Illuminate\Contracts\Auth\Access\Gate  $gate
  * @return void
  */
 public function boot(GateContract $gate)
 {
     $this->registerPolicies($gate);
     $gate->before(function ($user, $ability) {
         if (!$user->cmsEntry() && $ability != 'delete-comment') {
             return false;
         } else {
             if ($user->is('SuperAdmin') && $ability != 'change-user') {
                 return true;
             }
         }
     });
     $gate->define('change-user', function ($user, $user2) {
         if (($user->is('SuperAdmin') || $user->is('Admin')) && $user->rank() < $user2->rank()) {
             return true;
         }
         return false;
     });
     $gate->define('features', function ($user) {
         return $user->is('Admin');
     });
     $gate->define('create-post', function ($user) {
         return $user->is('Admin') || $user->is('Writer');
     });
     $gate->define('change-post', function ($user, $id) {
         if ($user->is('Writer')) {
             return $user->id == Post::find($id)->user_id;
         }
         return $user->is('Admin');
     });
     $gate->define('delete-comment', function ($user, $comment) {
         return $user->id == $comment->user->id;
     });
 }
开发者ID:emeyer161,项目名称:TheThirstyTerp,代码行数:40,代码来源:AuthServiceProvider.php

示例14: accept

 public function accept($id)
 {
     $offer = Offer::find($id);
     $post = Post::find($offer->post_id);
     $post->sold = $id;
     $post->save();
     $user = User::findOrFail($offer->user_id);
     $poster = User::findOrFail($offer->post_creator);
     $feedback_seller = new Feedback();
     $feedback_seller->post_id = $offer->post_id;
     $feedback_seller->giver_id = $offer->user_id;
     $feedback_seller->receiver_id = $offer->post_creator;
     $feedback_seller->type = 'seller';
     $feedback_seller->save();
     $feedback_buyer = new Feedback();
     $feedback_buyer->post_id = $offer->post_id;
     $feedback_buyer->giver_id = $offer->post_creator;
     $feedback_buyer->receiver_id = $offer->user_id;
     $feedback_buyer->type = 'buyer';
     $feedback_buyer->save();
     Mail::send('emails.offerAccepted', ['user' => $user, 'offer' => $offer, 'poster' => $poster, 'feedback' => $feedback_buyer], function ($m) use($user) {
         $m->to($user->email, $user->name)->subject('Offer Accepted!');
     });
     Mail::send('emails.listingSold', ['user' => $user, 'offer' => $offer, 'poster' => $poster, 'feedback' => $feedback_seller], function ($m) use($user) {
         $m->to($poster->email, $poster->name)->subject('Listing Sold!');
     });
     return Redirect($post->community_id . '/post/' . $post->id)->with('message', 'Offer Accepted');
 }
开发者ID:jakeboyles,项目名称:GuyBuy,代码行数:28,代码来源:OfferController.php

示例15: postLikePost

 public function postLikePost(Request $request)
 {
     $post_id = $request['postId'];
     $isLike = $request['isLike'] === 'true';
     // ? true  : false;
     $update = false;
     $post = Post::find($post_id);
     if (!$post) {
         return null;
     }
     $user = Auth::user();
     $like = $user->likes()->where('post_id', $post_id)->first();
     if ($like) {
         $alreadyLike = $like->like;
         $update = true;
         if ($alreadyLike == $isLike) {
             $like->delete();
             return null;
         }
     } else {
         $like = new Like();
     }
     $like->like = $isLike;
     $like->user_id = $user->id;
     $like->post_id = $post->id;
     if ($update) {
         $like->update();
     } else {
         $like->save();
     }
     return null;
 }
开发者ID:megmarcaida,项目名称:smixs,代码行数:32,代码来源:PostController.php


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