/** * View a blog post. * * @param string $slug * @return Redirect */ public function postView($slug) { $user = $this->user->currentUser(); $canComment = $user->can('post_comment'); if (!$canComment) { return Redirect::to($slug . '#comments')->with('error', 'You need to be logged in to post comments!'); } // Get this blog post data $post = $this->post->where('slug', '=', $slug)->first(); // Declare the rules for the form validation $rules = array('comment' => 'required|min:3'); // Validate the inputs $validator = Validator::make(Input::all(), $rules); // Check if the form validates with success if ($validator->passes()) { // Save the comment $comment = new Comment(); $comment->user_id = Auth::user()->id; $comment->content = Input::get('comment'); // Was the comment saved with success? if ($post->comments()->save($comment)) { // Redirect to this blog post page return Redirect::to($slug . '#comments')->with('success', 'Your comment was added with success.'); } // Redirect to this blog post page return Redirect::to($slug . '#comments')->with('error', 'There was a problem adding your comment, please try again.'); } // Redirect to this blog post page return Redirect::to($slug)->withInput()->withErrors($validator); }
public function post($link) { $table = Post::where('link', '=', $link)->firstOrFail(); $table->content = e($table->content); $table->save(); return View::make('blog.post', ['post' => Post::where('link', '=', $link)->firstOrFail()]); }
public function getComment() { $id = Auth::id(); $postList = Post::where("author_id", $id)->get(array('_id')); $postIdList = array(); foreach ($postList as $post) { // echo $post->_id; // echo "<br>"; array_push($postIdList, $post->_id); } $comment_data = Comment::whereIn('post_id', $postIdList)->get(); //echo count($comment_data); foreach ($comment_data as $comment) { $user_id = $comment['user_id']; $user = User::getUserById($user_id); $post = Post::where('_id', $comment->post_id)->first(); $comment['title'] = $post['title']; $comment['username'] = $user['username']; $comment['email'] = $user['email']; $format = "F j, Y, g:i a"; $date = new DateTime($comment['updated_at']); $formatDate = $date->format($format); $comment['update_time'] = $formatDate; if (isset($user['fb_img'])) { $comment['fb_img'] = $user['fb_img']; } } return View::make('backend.comment', array('comment_data' => $comment_data)); }
public function testLists() { $lists = Post::where('views', '>=', 10)->lists('id', 'title'); $debug = last(DB::getQueryLog()); $this->assertEquals(['Bar' => 2, 'FooBar' => 3], $lists); $this->assertEquals('select "id", "title" from "posts" where "published" = ? and "views" >= ? and "status" = ?', $debug['query']); }
/** * View a blog post. * * @param string $slug * @return Redirect */ public function postView($slug) { // The user needs to be logged in, make that check please if (!Sentry::check()) { return Redirect::to("blog/{$slug}#comments")->with('error', 'You need to be logged in to post comments!'); } // Get this blog post data $post = Post::where('slug', $slug)->first(); // Declare the rules for the form validation $rules = array('comment' => 'required|min:3'); // Create a new validator instance from our dynamic rules $validator = Validator::make(Input::all(), $rules); // If validation fails, we'll exit the operation now if ($validator->fails()) { // Redirect to this blog post page return Redirect::to("blog/{$slug}#comments")->withInput()->withErrors($validator); } // Save the comment $comment = new Comment(); $comment->user_id = Sentry::getUser()->id; $comment->content = e(Input::get('comment')); // Was the comment saved with success? if ($post->comments()->save($comment)) { // Redirect to this blog post page return Redirect::to("blog/{$slug}#comments")->with('success', 'Your comment was successfully added.'); } // Redirect to this blog post page return Redirect::to("blog/{$slug}#comments")->with('error', 'There was a problem adding your comment, please try again.'); }
/** * View a blog post. * * @param string $slug * @return Redirect */ public function postView($slug) { $user = $this->user->currentUser(); $canComment = $user->can('post_comment'); if (!$canComment) { return Redirect::to($slug . '#comments')->with('error', Lang::get('site.login_to_post')); } // Get this blog post data $post = $this->post->where('slug', '=', $slug)->first(); // Declare the rules for the form validation $rules = array('comment' => 'required|min:3', 'comment_hp' => 'honeypot', 'comment_time' => 'required|honeytime:5'); // Validate the inputs $validator = Validator::make(Input::all(), $rules); // Check if the form validates with success if ($validator->passes()) { // Save the comment $comment = new Comment(); $comment->user_id = Auth::user()->id; $comment->content = Input::get('comment'); // Was the comment saved with success? if ($post->comments()->save($comment)) { // Redirect to this blog post page return Redirect::to($slug . '#comments')->with('success', Lang::get('site.comment_added')); } // Redirect to this blog post page return Redirect::to($slug . '#comments')->with('error', Lang::get('site.comment_not_Added')); } // Redirect to this blog post page return Redirect::to($slug)->withInput()->withErrors($validator); }
public function __construct(Reservation $reservation) { $this->reservation = $reservation; View::share('locations', Location::orderBy('name', 'asc')->get()); View::share('types', Type::orderBy('name', 'asc')->get()); View::share('news', Post::where('post_type', 'news')->orderBy('created_at', 'desc')->limit(4)->get()); }
public function getAccount() { $news = Post::where('parent', '=', '7')->get(); $projects = Project::limit(10)->get(); $view = array('news' => $news, 'projects' => $projects); return View::make('user.account', $view); }
function post_list() { // only run on the first call if (!Registry::has('rwar_post_archive')) { // capture original article if one is set if ($article = Registry::get('article')) { Registry::set('original_article', $article); } } if (!($posts = Registry::get('rwar_post_archive'))) { $posts = Post::where('status', '=', 'published')->sort('created', 'desc')->get(); Registry::set('rwar_post_archive', $posts = new Items($posts)); } if ($result = $posts->valid()) { // register single post Registry::set('article', $posts->current()); // move to next $posts->next(); } else { // back to the start $posts->rewind(); // reset original article Registry::set('article', Registry::get('original_article')); // remove items Registry::set('rwar_post_archive', false); } return $result; }
/** * TODO: Documentation * @param type $groupid * @return type */ public function showStatusPage($groupid) { if (empty($groupid)) { App::abort(404); } $user = Auth::user(); $group = Group::find($groupid); // I will have to fetch the user's current group $userCurrentTask = $user->getPendingTask($group->id, $group->outcome); if ($userCurrentTask) { $task = Task::find($userCurrentTask[0]->task_id); // I will have to fetch the user's curent task } else { $task = Task::find(5); } // TODO: fetch the posts for this group $posts = Post::orderBy('id', 'DESC')->where('group_id', $group->id)->take(5)->get(); $postCount = Post::where('group_id', $group->id)->count(); $current = new stdClass(); $current->user = $user->id; $current->group = $group->id; $current->task = $task->id; $this->layout->bodyclasses = 'status-page'; $this->layout->content = View::make('play.status')->with('user', $user)->with('group', $group)->with('task', $task)->with('current', $current)->with('posts', $posts)->with('postcount', $postCount); }
/** * @name getPagesDatatables * * Gets data for pages datatables * * @return Response - returns Respons in json format including data for datatables or error */ public function getPagesDatatables() { $pages = Post::where('type', 'page')->whereNotIn('status', array('trash', 'auto-draft')); $total = $pages->count(); $result = $pages->with("post_contents")->get()->toArray(); return Response::json(array("sEcho" => 1, "iTotalRecords" => $total, "iTotalDisplayRecords" => $total, "aaData" => $result)); }
/** * Display the specified category. * * @param string $slug * @return Response */ public function show($slug) { //return le slug de la categorie $categories = Category::where('slug', $slug)->firstOrFail(); $posts = Post::where('category_id', '=', $categories->id)->orderBy('published_at', 'desc')->paginate(5); return View::make('categories.show', compact('categories', 'posts', 'author')); }
public function index() { $page = Post::where('permalink', '=', 'welcome')->first(); $slides = Slideshow::latest()->get(); $this->layout->title = 'Home'; $this->layout->content = View::make('public.' . $this->current_theme . '.index')->with('page', $page)->with('slides', $slides); }
public function get_parent() { if (isset($this->parent)) { return $this->parent; } $this->parent = Post::where(['id' => $this->parent_id])->first(); return $this->parent; }
public function index() { $victories = Victory::orderBy('created_at', 'DESC')->limit(4)->get(); $blogs = Blog::orderBy('created_at', 'DESC')->limit(4)->get(); $images = Post::where('is_carasaul', '=', 1)->get(); $testimonials = Testimonial::orderBy('created_at', 'DESC')->limit(1)->get(); return View::make('pages.index', compact('images', 'testimonials', 'victories', 'blogs')); }
public function index() { if (Input::has('title')) { $title = Input::get('title'); $posts = Post::where('title', 'like', '%' . $title . '%')->take(5)->get(); return Response::json(['data' => $posts]); } }
public function approve($user_id, $ip_addr) { self::connection()->executeSql("UPDATE tag_implications SET is_pending = FALSE WHERE id = " . $this->id); $t = Tag::find($this->predicate_id); $implied_tags = implode(' ', self::with_implied(array($t->name))); foreach (Post::where("id IN (SELECT pt.post_id FROM posts_tags pt WHERE pt.tag_id = ?)", $t->id)->take() as $post) { $post->updateAttributes(array('tags' => $post->cached_tags . " " . $implied_tags, 'updater_user_id' => $user_id, 'updater_ip_addr' => $ip_addr)); } }
public function deletePost($id) { $post = Post::where('id', $id)->delete(); if ($post) { return Redirect::back()->with('flash_success', "Deleted successfully"); } else { return Redirect::back()->with('flash_error', "Something went wrong"); } }
public static function menu() { $new_sub = array(); foreach (Newtypes::all() as $val) { $new_sub[$val->id]['name'] = $val->name; $new_sub[$val->id]['val'] = Post::where('category', '=', $val->id)->take(10)->get(); } return $new_sub; }
public function search() { //TODO Rate limit $query = Input::get('query'); $max = Input::has('size') && Input::get('size') < 61 ? Input::get('size') : 25; $last = Input::has('last') ? Input::get('last') : Post::orderBy('id', 'desc')->first()->id; $posts = Post::where('text', 'ilike', '%' . $query . '%')->where('id', '<', $last)->orderBy('id', 'desc')->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->take($max)->get(); return $this->respond($this->collectionTransformer->transformPosts($posts)); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $post = Post::where('id', $id)->orWhere('slug', $id)->first(); if (!$post) { Session::flash('errorMessage', 'This post does not exist.'); return Redirect::route('posts.index'); } return View::make('posts.show')->with('post', $post); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $post = Post::where('id', '=', $id)->first(); $answer = Post::where('id', '=', $post->accepted_answer_id)->first(); $answers = Post::with(array('votes'))->where('parent_id', '=', $post->id)->where('id', "<>", $post->accepted_answer_id)->get(); $tags = Tag::all(); $data = array('post' => $post, 'answer' => $answer, 'answers' => $answers, 'tags' => $tags); return View::make('public.question.index', $data); }
private static function chanStat() { $chans = DB::table('posts')->where('parent_id', '=', 0)->where("chan", "!=", "")->where('timestamp', '>', Carbon\Carbon::now()->subWeek())->lists('chan'); $result = []; foreach ($chans as $c) { $result[$c] = Post::where('chan', $c)->count(); } arsort($result); return array_slice($result, 0, 30); }
/** @test **/ public function it_returns_the_fresh_model_fetched_from_the_database() { $this->createPostsTable(); $this->insertOn('posts', ['title' => 'Psych!', 'content' => 'GUUUS!!!']); $post = Post::where('title', 'Psych!')->first(); $post->title = 'House'; $post = $post->fresh(); $this->assertEquals('Psych!', $post->title); $this->assertEquals('GUUUS!!!', $post->content); }
/** * Display the specified resource. * GET /posts/{id} * * @param string $slug * @return Response */ public function show($slug) { $post = Post::where('slug', $slug)->firstOrFail(); $author = $post->user; //recuperer les socials link $socials = Social::all(); /*$cat = $post->category();*/ $comments = $post->comments; return View::make('posts.show', compact('post', 'author', 'comments', 'tags', 'socials')); }
public function categoryList($category = null) { if ($category) { $posts = Post::where('category', '=', $category)->where('draft', '=', 0)->orderBy('created_at', 'desc')->paginate(10); } else { $posts = Post::where('draft', '=', 0)->orderBy('created_at', 'desc')->paginate(10); } $this->layout->title = 'Liste de la catégorie'; $this->layout->main = View::make('home')->nest('content', 'index', compact('posts')); }
function home_latest_post() { $post = Post::where('status', '=', 'published')->sort('created', 'desc')->take(1)->fetch(); if ($post) { // set globally to use article theming functions Registry::set('article', $post); // or you can just return and use the raw object return $post; } }
private static function statGroups() { $groups = DB::table('posts')->where('parent_id', '=', 0)->where('timestamp', '>', Carbon\Carbon::now()->subMonth())->whereIn('group_name', Group::where('is_featured', 1)->lists('group_name'))->lists('group_name'); $result = []; foreach ($groups as $g) { $result[$g] = Post::where('group_name', '=', $g)->count(); } arsort($result); return array_slice($result, 0, 30); }
public function testBasicWhereTranslated() { $queryAnd = Post::where('title', 'my title'); $queryOr = Post::where('is_active', 1)->orWhere('title', 'my title'); $expected = 'select "posts".*, "posts_i18n"."title", "posts_i18n"."body" from "posts" ' . 'left join "posts_i18n" on "posts_i18n"."post_id" = "posts"."id" and "posts_i18n"."locale" = ? '; $this->assertEquals($queryAnd->toSql(), $expected . 'where "posts_i18n"."title" = ?'); $this->assertEquals(['en', 'my title'], $queryAnd->getBindings()); $this->assertEquals($queryOr->toSql(), $expected . 'where "is_active" = ? or "posts_i18n"."title" = ?'); $this->assertEquals(['en', 1, 'my title'], $queryOr->getBindings()); }
function article_next_url() { $page = Registry::get('posts_page'); $query = Post::where('created', '>', Registry::prop('article', 'created'))->where('status', '!=', 'draft'); if ($query->count()) { $article = $query->sort('created', 'asc')->fetch(); $page = Registry::get('posts_page'); return base_url($page->slug . '/' . $article->slug); } }