public function upload() { $uploader_id = Auth::user()->active_contact->id; if (Input::file('file')->isValid()) { if (Input::get('target') == "posts") { if (Input::get('target_action') == "create") { $target = Post::where('author_id', $uploader_id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", Input::get('target_id'))->first(); } elseif (Input::get('target_action') == "edit") { $target = Post::where("id", Input::get('target_id'))->first(); } } elseif (Input::get('target') == "tickets") { if (Input::get('target_action') == "create") { $target = Ticket::where('status_id', TICKET_DRAFT_STATUS_ID)->where('creator_id', $uploader_id)->first(); } elseif (Input::get('target_action') == "edit") { $target = Ticket::where("id", Input::get('target_id'))->first(); } } $id = $target->id; $request['target_id'] = $id; $request['uploader_id'] = $uploader_id; $request['file'] = Input::file('file'); $request['target'] = Input::get('target'); $request['target_action'] = Input::get('target_action'); $response = $this->repo->upload($request); $response = Response::json($response, 200); return $response; } }
public static function getPosts($post_id) { $photo_id = Post::where('post_id', $post_id)->get(['photo_link'])[0]["photo_link"]; $list_id = PostRecommendView::where("photo_id", $photo_id)->orderBy("rank", "desc")->take(10)->get(["post_id_recommend"]); $results = UserPosts::whereIn("post_id", $list_id)->distinct('photo_link')->get(); return $results; }
/** * Store a newly created Comment in storage. * POST /comments * * @param Request $request * * @return Response */ public function store(Request $request) { if (sizeof(Comment::$rules) > 0) { $validator = $this->validateRequestOrFail($request, Comment::$rules); if ($validator) { return $validator; } } $input = $request->all(); $input['objectId'] = str_random(10); $comments = $this->commentRepository->create($input); if (isset($input['postType']) && $input['postType'] == 'iWomenPost') { $post = IwomenPost::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'Post') { $post = Post::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'SubResourceDetail') { $post = SubResourceDetail::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'Resources') { $post = Resources::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } } } } if (isset($input['postType']) && $input['postType'] == 'Post' || isset($input['postType']) && $input['postType'] == 'SubResourceDetail' || isset($input['postType']) && $input['postType'] == 'Resources') { if (isset($post) && $post) { $device_list = []; $gcm = Gcm::where('user_id', $post->userId)->first(); if ($gcm) { $device_list[] = PushNotification::Device($gcm->reg_id); $message['title'] = 'New Comment'; $message['message'] = $comments->comment_contents; $devices = PushNotification::DeviceCollection($device_list); $message = PushNotification::Message(json_encode($message), array()); $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message); } } } $comments['comment_count'] = $post->comment_count; return $this->sendResponse($comments->toArray(), "Comment saved successfully"); }
public static function getBoardById($board_id) { $result["board"] = Board::where('board_id', $board_id)->first(); $result["posts"] = UserPosts::where('board_id', $board_id)->get(); $result["board"]["cover_link"] = $result["posts"][0]["photo_link"]; $result["profile"]["number_of_posts"] = Post::where('board_id', $board_id)->count(); $result["profile"]["number_of_following"] = FollowEvent::countFollower($board_id); return $result; }
public static function getPreviewBoard($board_id) { $list = new \SplFixedArray(4); $posts = Post::where('board_id', $board_id)->take(4)->get(['photo_link']); for ($i = 0; $i < count($posts); $i++) { $list[$i] = url('api/photo' . '/' . $posts[$i]['photo_link']); } return $list; }
/** * Return data for a tag index page * * @param string $tag * @return array */ protected function tagIndexData($tag) { $tag = Tag::where('tag', $tag)->firstOrFail(); $reverse_direction = (bool) $tag->reverse_direction; $posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function ($q) use($tag) { $q->where('tag', '=', $tag->tag); })->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('upload.posts_per_page')); $posts->addQuery('tag', $tag->tag); $page_image = $tag->page_image ?: config('upload.page_image'); return ['title' => $tag->title, 'subtitle' => $tag->subtitle, 'posts' => $posts, 'page_image' => $page_image, 'tag' => $tag, 'reverse_direction' => $reverse_direction, 'meta_description' => $tag->meta_description ?: config('upload.description')]; }
public function search(Request $request) { $search = $request->keywords ? $request->keywords : ''; $offset = $request->page ? $request->page : 1; $limit = $request->limit ? $request->limit : 12; $isAllow = $request->isAllow ? $request->isAllow : 1; $category = $request->category; $offset = ($offset - 1) * $limit; $posts = Post::where('title', 'like', '%' . $search . '%')->orwhere('titleMm', 'like', '%' . $search . '%')->orwhere('content', 'like', '%' . $search . '%')->orwhere('content_mm', 'like', '%' . $search . '%')->orwhere('postUploadName', 'like', '%' . $search . '%')->where('isAllow', $isAllow)->where('category_id', $category)->orderBy('postUploadedDate', 'desc')->offset($offset)->limit($limit)->get(); return response()->json($posts); }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if (!parent::authorize()) { return false; } if ($this->blog) { if ($this->user()->isAdmin()) { return true; } return Post::where('id', $this->blog)->where('user_id', $this->user()->id)->exists(); } return true; }
public function show($id) { if (Auth::user()->can('read-ticket')) { $data['ticket'] = self::API()->find(['id' => $id]); if ($data['ticket']) { $data['title'] = "Ticket #" . $data['ticket']->id; $data['menu_actions'] = [Form::editItem(route('tickets.edit', $id), "Edit This Ticket", Auth::user()->can('update-ticket'))]; $data['ticket']['posts'] = PostsController::API()->all(['where' => ['ticket_id|=|' . $id], "order" => ['posts.created_at|ASC'], "paginate" => "false"]); $data['ticket']['history'] = TicketHistory::where('ticket_id', '=', $id)->orderBy('created_at')->get(); $data['statuses'] = Status::where('id', TICKET_WFF_STATUS_ID)->orWhere('id', TICKET_SOLVED_STATUS_ID)->get(); $data['draft_post'] = Post::where("ticket_id", $id)->where("status_id", POST_DRAFT_STATUS_ID)->where("author_id", Auth::user()->active_contact->id)->first(); $data['important_post'] = null; if (in_array($data['ticket']->status_id, [TICKET_SOLVED_STATUS_ID, TICKET_WFF_STATUS_ID])) { foreach ($data['ticket']['posts']->reverse() as $post) { if ($post->ticket_status_id != $data['ticket']->status_id) { break; } else { $data['important_post'] = $post; } } } $links = []; $temp = TicketLink::where("ticket_id", "=", $id)->get(); foreach ($temp as $elem) { $links[] = $elem->linked_ticket_id; } $data['ticket']['links'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $links)]]); $linked_to = []; $temp = TicketLink::where("linked_ticket_id", "=", $id)->get(); foreach ($temp as $elem) { $linked_to[] = $elem->ticket_id; } $data['ticket']['linked_to'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $linked_to)]]); if (isset($data['important_post'])) { switch ($data['ticket']->status_id) { case TICKET_WFF_STATUS_ID: $data['important_post']->alert_type = "danger"; break; case TICKET_SOLVED_STATUS_ID: $data['important_post']->alert_type = "success"; break; } } return view('tickets/show', $data); } else { return redirect()->back()->withErrors(['404 The following Ticket coudn\'t be found']); } } else { return redirect()->back()->withErrors(['Access denied to tickets show page']); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $post = Post::with(array('User' => function ($query) { $query->select('id', 'name'); }))->find($id); if (!$post) { return Response::json(['error' => ['message' => 'Post does not exist']], 404); } // get previous joke id $previous = Post::where('id', '<', $post->id)->max('id'); // get next joke id $next = Post::where('id', '>', $post->id)->min('id'); return Response::json(['previous_joke_id' => $previous, 'next_joke_id' => $next, 'data' => $this->transform($post)], 200); }
public static function add($data) { try { $post = Post::where('code', '=', $data['code'])->first(); if (is_null($post)) { $post = Post::create(array('name' => $data['name'], 'code' => $data['code'], 'public_date' => date('Y-m-d H:i:s'), 'preview_text' => Purifier::clean($data['preview_text']), 'text' => Purifier::clean($data['text']), 'user_id' => Auth::user()->id)); } else { return false; } } catch (Exception $e) { Log::info('Post:add(): ' . $e->getMessage()); return false; } return $post; }
public function store(CreatePostRequest $request) { $draft = $draft = Post::where('author_id', Auth::user()->active_contact->id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", $request->get("ticket_id"))->first(); $post = $draft ? $draft : new Post(); $post->ticket_id = $request->get('ticket_id'); $post->post = $request->get('post'); $post->author_id = Auth::user()->active_contact->id; $post->status_id = $request->get('is_public') ? POST_PUBLIC_STATUS_ID : POST_PRIVATE_STATUS_ID; $post->ticket_status_id = $request->get('status_id'); if (isset($post->updated_at)) { $post->created_at = $post->updated_at; } $post->save(); $ticket_updated = $this->updateTicket($request); EmailsManager::sendPost($post->id, $ticket_updated, $request->get('emails')); SlackManager::sendPost($post, $ticket_updated); return redirect()->route('tickets.show', $request->input('ticket_id'))->with('successes', ['Post created successfully']); }
public static function setRecommend() { $user_id = Auth::user()->user_id; $list_post = Post::where("user_id", '!=', $user_id)->get(); foreach ($list_post as $post) { // $list_id = (array) DB::select(DB::raw("SELECT * FROM user_posts WHERE user_id != ".$user_id." ORDER BY RAND() LIMIT 10")); $list_id = Post::where("user_id", "!=", $user_id)->orderByRaw("rand()")->distinct('photo_link')->take(5)->get(); foreach ($list_id as $id) { $recommend = new PostRecommend(); $recommend->photo_id = $post["photo_link"]; $recommend->photo_id_recommend = $id["photo_link"]; $recommend->rank = 1.0; $recommend->save(); } // print_r($post); } return $list_id; }
/** * Bootstrap any application services. * * @return void */ public function boot() { $author = User::whereHas('role', function ($q) { $q->where('slug', 'admin'); })->first(); $categories = Category::where('is_active', 1)->get(); $postsRecents = Post::where('is_active', 1)->where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get(); $postsPopular = Post::where('is_active', 1)->where('seen', 1)->orderBy('nview', 'desc')->take(3)->get(); $commentsRecents = Comment::where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get(); $tags = Tag::all(); $INFO_SITE = Admin::first(); view()->share('author', $author); view()->share('categories', $categories); view()->share('tags', $tags); view()->share('postsRecents', $postsRecents); view()->share('postsPopular', $postsPopular); view()->share('commentsRecents', $commentsRecents); view()->share('INFO_SITE', $INFO_SITE); }
/** * دریافت پست بر اساس ایدی و در صورتیکه درخواست کننده ادمین باشد * و دسترسی به هر نوع پست غیرفعال نیز دارد * * @param int $pst_id * @return Illuminate\Support\Collection */ public function getIsAdmin($pst_id) { $Res = $this->model->where('pst_id', "{$pst_id}")->first(); $this->AddJalaliDate($Res, " ", false); return $Res; }
public function addPostMsg($id) { $msg = Post::where('id', '=', $id)->firstOrFail(); return view('msg', $msg); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Post $post) { $posts = Post::where('archive_id', $post->archive_id)->get(); if (sizeof($posts) <= 1) { $post->delete(); Archive::find($post->archive_id)->delete(); } else { $post->delete(); } }
switch ($kind) { case '1': $kind = "Tất cả"; $result = Post::where("location", "LIKE", "%{$location}%")->where("title", 'LIKE', "%{$value}%")->get()->toArray(); break; case '2': $kind = "Ô tô, xe máy"; $result = Post::where("location", "LIKE", "%{$location}%")->where("category_id", '=', "3")->where("title", 'LIKE', "%{$value}%")->get()->toArray(); break; case '3': $kind = "Nhà đất"; $result = Post::where("location", "LIKE", "%{$location4}")->where("category_id", '=', "1")->orWhere("category_id", '=', "2")->where("title", 'LIKE', "%{$value}%")->get()->toArray(); break; case '4': $kind = "Điện thoại, Laptop"; $result = Post::where("location", "LIKE", "%{$location}%")->where("category_id2", '=', "16")->orWhere("category_id2", '=', "17")->where("title", 'LIKE', "%{$value}%")->get()->toArray(); break; default: break; } if (!empty($result)) { $count = count($result); return View::make("tim_kiem", array("result" => $result, "count" => $count, "kind" => $kind, "key" => $value)); } else { return View::make("tim_kiem", array("result" => "", "kind" => $kind, "key" => $value)); } }); Route::get("/test/{name}/{value}", function ($name, $value) { print_r(Users::whereLike($name, $value)); }); Route::get("member/test2/{user_id}", function ($user_id) {
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $user_id = Auth::user()->id; $letters = Post::where('receiver_id', '=', $user_id)->get(); return view('post.letter_index', ['letters' => $letters]); }
public static function getPostsInBoard($board_id) { $posts = Post::where('board_id', $board_id)->orderBy('updated_at')->get(); return $posts; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request */ public function update(RulesPostRequest $request) { $post = Post::where('id', $request->input('id'))->firstOrFail(); $post->update($request->all()); return redirect('/'); }
protected function getPostsCount() { return Post::where('created_at', '<=', Carbon::now())->where('post_status', 1)->orderBy('created_at', 'desc')->count(); }
public static function countPostsByUserId($user_id) { $posts = Post::where('user_id', $user_id)->count(); return $posts; }
public function getUserPost($id = NULL) { return $id == NULL ? view('home') : Post::where('id_user', '=', $id)->latest()->get(); }
public function search(SearchRequest $request) { try { $word = $request->input('search'); $posts = Post::where('seen', 1)->where('is_active', 1)->orderBy('created_at', 'desc')->where('summary', 'like', '%' . $word . '%')->orWhere('content', 'like', '%' . $word . '%')->paginate($this->itemPerPage); return view('website.index', compact('posts')); } catch (Exception $e) { $message = "Không tồn tại bài viết nào."; $alertClass = "alert-danger"; return redirect(route('website.index'))->with(compact('message', 'alertClass')); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function delete($id) { $flag = Post::where('posts_id', $id)->delete(); if ($flag) { return response()->json(['status' => true, 'message' => '数据删除成功']); } else { return response()->json(['status' => false, 'message' => '数据删除失败']); } }
public function index() { $userId = \Auth::user()->id; $postList = Post::where('user_id', '=', $userId)->orderBy('updated_at', 'DESC')->get(); return view('post.index', compact('postList')); }
public function index() { $posts = \App\Models\Post::where('publish', 1)->paginate(3); return view('post.index', ['posts' => $posts]); }
public function getHome() { $posts = Post::where('published', 1)->paginate(5); return view('home')->with(['posts' => $posts]); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request, $id) { $post = Post::find($id); if (!$this->canModify($post, $request->user())) { return redirect('/')->withErrors('You do not have sufficient permissions to edit this post'); } $title = $request->input('title'); $slug = str_slug($title); $duplicate = Post::where('slug', $slug)->first(); if ($duplicate && $duplicate->id != $post_id) { return redirect('edit/' . $post->slug)->withErrors('Title already exists.')->withInput(); } $post->slug = $slug; $post->title = $title; $post->body = $request->input('body'); if ($request->has('save')) { $post->active = 0; $message = 'Post saved successfully'; $landing = 'edit/' . $post->slug; } else { $post->active = 1; $message = 'Post updated successfully'; $landing = $post->slug; } $post->save(); return redirect($landing)->withMessage($message); }