本文整理汇总了PHP中app\models\Post::getPostById方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::getPostById方法的具体用法?PHP Post::getPostById怎么用?PHP Post::getPostById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::getPostById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNewNotification
/**
* @param $sender
* @param $receiver
* @param $object
*/
private static function createNewNotification($sender, $event)
{
$noti = new Notification();
$noti["sender_id"] = $sender;
$noti["is_read"] = 0;
$noti["objectType"] = POST;
if ($event instanceof FollowEvent) {
$noti["type"] = FOLLOW;
$noti["receiver_id"] = $event["following_id"];
if ($event["follow_type"] == 2) {
$noti["objectType"] = BOARD;
} else {
$noti["objectType"] = USER;
}
} else {
$post = Post::getPostById($event["post_id"]);
$noti["receiver_id"] = $post["user_id"];
if ($event instanceof LikeEvent) {
$noti["type"] = LIKE;
$noti["objectID"] = $event["post_id"];
} else {
if ($event instanceof CommentEvent) {
$noti["type"] = COMMENT;
$noti["objectID"] = $event["post_id"];
} else {
if ($event instanceof PinEvent) {
$noti["type"] = PIN;
$noti["objectID"] = $event["post_id"];
}
}
}
}
return $noti;
}
示例2: delete
/**
* Delete post
*
* @param Request $request
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function delete(Request $request, $id = 0)
{
if ($request->isMethod('post')) {
foreach ($request->input('posts') as $post) {
$post = Post::getPostById($post);
if (!empty($post)) {
if (!empty($post->image)) {
if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
}
}
$post->delete();
}
}
} else {
$post = Post::getPostById($id);
if (!empty($post)) {
if (!empty($post->image)) {
if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
}
}
$post->delete();
}
return redirect()->back();
}
}
示例3: likePost
public function likePost($post_id)
{
if (!Auth::check()) {
return response()->json('Please login');
}
$current_id = Auth::user()->user_id;
$avatar_link = Auth::user()->avatar_link;
$name = Auth::user()->name;
$post = LikeEvent::checkLiked($post_id, $current_id);
$channel = Post::getPostById($post_id)["user_id"];
if (!$post) {
$result = LikeEvent::createLikeEvent($post_id, $current_id);
$pusher = App::make('pusher');
$pusher->trigger($channel, 'like', array('name' => $name, 'post_id' => $post_id, 'avatar_link' => $avatar_link));
} else {
$result = LikeEvent::removeLikeEvent($post["like_event_id"]);
}
return response()->json(["result" => $result]);
}
示例4: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($post_id)
{
//
$post = $this->getPostDetail($post_id)[0];
$post_stat = $this->getPostDetail($post_id)[1];
if (Auth::check()) {
$post["liked"] = LikeEvent::checkLiked($post["post_id"], Auth::user()->user_id);
}
$post["comments"] = Post::getCommentsByPostId($post_id);
$post["likes"] = $post_stat["likes"];
$post["pins"] = $post_stat["pins"];
$post["boards"] = Board::getPostsInBoard($post["board_id"]);
$post["places"] = Place::getPlaceById(Post::getPostById($post_id)['place_id']);
$recommend = new RecommendController();
$post["recommend_posts"] = $recommend->getPost($post_id);
return response()->json($post);
}
示例5: disapprove
/**
* Disapprove post
*
* @param $id
* @return \Illuminate\Http\RedirectResponse
*/
public function disapprove($id)
{
$post = Post::getPostById($id);
if ($post) {
$post->approve = 0;
$post->save();
if ($post->author_id != Auth::user()->id) {
$notification = new Notification();
$notification->from = Auth::user()->id;
$notification->to = $post->author_id;
$notification->type = 6;
$notification->save();
}
}
return redirect()->route('admin_posts');
}
示例6: getPost
public function getPost($post_id)
{
$client = new Client();
$post = Post::getPostById($post_id);
$index_name = Config::get('elasticsearch.index_name');
$post_type = Config::get('elasticsearch.post_type');
$params = ["index" => $index_name, "analyzer" => 'vi_analyzer', 'text' => $post["description"]];
$tokens = $client->indices()->analyze($params)["tokens"];
$search = new SearchController();
$results = [];
foreach ($tokens as $token) {
$query = ["description" => $token["token"]];
$results[] = $search->search($post_type, $query);
}
return $results;
}