Example #1
0
 /**
  * GET /posts
  * Get a listing of all posts.
  *
  * @return Response
  */
 public function index()
 {
     $posts = $this->post->with('tags', 'series')->published()->latest()->paginate(10);
     $page = Input::get('page');
     $title = $page ? "All posts (Page {$page})" : 'All posts';
     return View::make('posts.index', compact('posts'))->withTitle($title);
 }
 /**
  * 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);
 }
 /**
  * Display posts by category
  */
 public function getByCategory($category = 'all')
 {
     if ($category == 'all') {
         $posts = Post::with('user')->orderBy('id', 'desc')->paginate(15);
     } else {
         $posts = Post::with('user')->where('category', $category)->orderBy('id', 'desc')->paginate(15);
     }
     return View::make('posts.index')->with(['posts' => $posts, 'category' => $category]);
 }
Example #4
0
 public function postsApi()
 {
     $posts = \Post::with(['user' => function ($query) {
         // getting the ID field is necessary
         $query->select(['id', 'username']);
         // user_id is required to enable eager loading
     }])->get(['id', 'title', 'status', 'user_id']);
     return \Response::json($posts);
 }
 public function index()
 {
     // hard-coding autologin of User #2,
     // so we don't have to implement Auth for the scope of this demo.
     $user = User::find(2);
     Auth::login($user);
     // get recent posts, and eager load texts
     $posts = Post::with('text')->orderBy('created_at', 'desc')->get();
     $this->layout->content = View::make('home')->with('posts', $posts);
 }
 public function show($id)
 {
     $user = User::find($id);
     $posts = Post::with('user')->where('user_id', $id)->orderBy('created_at', 'desc')->paginate(4);
     if ($user != null) {
         return View::make('showuser')->with('user', $user)->with('posts', $posts);
     } else {
         App::abort(404);
     }
 }
Example #7
0
 public function index()
 {
     // 	Eloquent collection
     // 	$posts = Post::all();
     $posts = Post::with('user')->paginate(2);
     // Pagination collection
     // $perPage = Input::get('per-page'); you then pass $perpage into the paginate
     // $posts = Post::paginate(2);
     return View::make('posts.index')->with(array('posts' => $posts));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $query->where('title', 'like', '%' . Input::get('search') . '%');
         $query->orWhere('body', 'like', '%' . Input::get('search') . '%');
     }
     $posts = $query->orderBy('id', 'desc')->paginate(14);
     return View::make('posts.index')->with('posts', $posts);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('post', function ($value) {
         return Post::with('user')->where('slug', $value)->first();
     });
     $router->bind('comment', function ($value) {
         return Comment::with('user')->where('id', $value)->first();
     });
 }
Example #10
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (Auth::id() != $id) {
         Log::info('This user id is not equal');
         return Redirect::action('UsersController@show', Auth::id());
     }
     $post = Post::with('user')->get();
     $user = User::find($id);
     return View::make('users.edit', compact('user'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $search = Input::get('search');
         $query->where('title', 'like', "%{$search}%")->orWhere('body', 'like', "%{$search}%");
     }
     $posts = $query->orderBy('created_at', 'desc')->paginate(5);
     return View::make('posts.index')->with('posts', $posts);
 }
Example #12
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // $posts = Post::paginate(4);
     // $data = array(
     // 	'posts'=> $posts
     // );
     // return View::make('posts.index')->with($data);
     $posts = Post::with('user')->orderBy('created_at', 'desc')->paginate(4);
     return View::make('posts.index')->with('posts', $posts);
 }
Example #13
0
 public function blog($page = 1)
 {
     $limit = 5;
     $offset = ($page - 1) * $limit;
     $posts = Post::take($limit)->skip($offset)->active()->orderBy('created_at', 'desc')->get();
     Paginator::setBaseUrl(Config::get('app.url') . '/blog');
     Paginator::setCurrentPage($page);
     $totalItems = Post::with('id')->active()->count();
     $paginator = PrettyPaginator::make($posts->toArray(), $totalItems, $limit);
     return View::make('blog.blog', ['posts' => $posts, 'paginate' => $paginator]);
 }
Example #14
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $search = Input::get('search');
     if ($search) {
         $query = Post::with('user')->where('title', 'LIKE', '%' . $search . '%')->orWhere('body', 'LIKE', '%' . $search . '%')->orWhere('location', 'LIKE', '%' . $search . '%');
     } else {
         $query = Post::with('user');
     }
     $posts = $query->orderBy('created_at', 'desc')->paginate(30);
     return View::make('posts.index')->with(['posts' => $posts, 'search' => $search]);
 }
Example #15
0
 public function search()
 {
     $search = Input::get('search');
     $searchTerms = explode(' ', $search);
     $queryPost = Post::with('user');
     foreach ($searchTerms as $term) {
         $queryPost->where('title', 'LIKE', '%' . $term . '%')->orWhere('content', 'LIKE', '%' . $term . '%');
     }
     $posts = $queryPost->orderBy('created_at', 'desc')->get();
     $tags = Tag::with('posts')->paginate(8);
     return View::make('search', compact('posts', 'tags'));
 }
 public function newPosts()
 {
     if (Auth::check()) {
         $auth_user_id = Auth::user()->id;
         $posts = Post::with(array('user', 'follows' => function ($query) use($auth_user_id) {
             $query->where('user_id', '=', $auth_user_id);
         }))->orderBy('created_at', 'desc')->paginate(25);
     } else {
         $posts = Post::with('user')->paginate(25);
     }
     return View::make('new', compact('posts'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //show all listings here
     $query = Post::with('user');
     $search = Input::get('search');
     if (Input::has('search')) {
         $query->where('title', 'like', '%' . $search . "%")->orWhere('body', 'like', '%' . $search . "%")->orWhereHas('user', function ($q) use($search) {
             $q->where('first_name', 'like', '%' . $search . "%")->orWhere('last_name', 'like', '%' . $search . "%");
         });
     }
     $posts = $query->orderBy('created_at', 'desc')->paginate(10);
     return View::make('posts.index')->with('posts', $posts);
 }
Example #18
0
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $query->where('title', 'like', '%title%');
         $query->orWhere('body', 'like', '%body%');
         $query->orWhereHas('user', function ($q) {
             $q->where('email', 'like', '%bee%');
         });
     }
     $posts = $query->paginate(4);
     // $posts = Post::with('user')->orderBy('updated_at', 'desc')->paginate(4);
     return View::make('posts.index')->with('posts', $posts);
 }
Example #19
0
 public function search()
 {
     $search = Input::get('search');
     $searchTerms = explode(' ', $search);
     $queryPost = Post::with('user');
     $queryUser = User::with('post');
     foreach ($searchTerms as $term) {
         $queryPost->where('title', 'LIKE', '%' . $term . '%')->orWhere('body', 'LIKE', '%' . $term . '%')->orWhere('location', 'LIKE', '%' . $term . '%');
         $queryUser->where('username', 'LIKE', '%' . $term . '%')->orWhere('email', 'LIKE', '%' . $term . '%')->orWhere('location', 'LIKE', '%' . $term . '%');
     }
     $resultsPost = $queryPost->orderBy('created_at', 'desc')->get();
     $resultsUser = $queryUser->orderBy('created_at', 'desc')->get();
     return View::make('search')->with(['resultsPost' => $resultsPost, 'resultsUser' => $resultsUser]);
 }
 public function displayAllPosts()
 {
     $postViews = array();
     $posts = Post::with('author', 'tags')->get();
     foreach ($posts as $post) {
         Log::debug('Rendering a post: Title = ' . $post->title . '; Author = ' . $post->author->name . '; Created at = ' . $post->created_at . '; Tags:');
         foreach ($post->tags as $tag) {
             Log::debug('Tag = ' . $tag->name);
         }
         $postView = View::make('post')->with('post', $post)->with('author', $post->author)->with('tags', $post->tags);
         array_push($postViews, $postView);
     }
     return View::make('home')->with('posts', $postViews);
 }
 public function displayTag($tag)
 {
     $query = Post::with('user');
     if (strpos($tag, "+")) {
         $firstKey = substr($tag, 0, strpos($tag, "+"));
         $query->where('tags', '=', "{$firstKey}");
         $query->orWhere('tags', 'like', '%' . "{$firstKey}" . '%');
     } else {
         $query->where('tags', '=', "{$tag}");
         $query->orWhere('tags', 'like', '%' . "{$tag}" . '%');
     }
     $showQuery = $query->orderBy('created_at', 'desc')->paginate(5);
     return View::make('/tag')->with('tags', $showQuery);
 }
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return View
  * @throws NotFoundHttpException
  */
 public function getView($slug)
 {
     // Get this blog post data
     $post = Post::with('comments', 'author')->where('slug', $slug)->first();
     // Check if the blog post exists
     if (is_null($post)) {
         // If we ended up in here, it means that a page or a blog post
         // don't exist. So, this means that it is time for 404 error page.
         return App::abort(404);
     }
     // Get this post comments
     $comments = $post->comments()->with('author')->orderBy('created_at', 'DESC')->get();
     // Show the page
     return View::make('frontend/blog/view-post', compact('post', 'comments'));
 }
Example #23
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $query = Post::with('user');
     $search = Input::get('search');
     if ($search) {
         $query->where('title', 'like', "%{$search}%");
         $query->orWhere('subtitle', 'like', "%{$search}%");
         $query->orWhere('body', 'like', "%{$search}%");
         $query->orWhereHas('user', function ($q) use($search) {
             $q->where('email', 'like', "%{$search}%");
         });
     }
     $posts = $query->orderBy('updated_at', 'desc')->paginate(4);
     return View::make('blog')->with('posts', $posts);
 }
 public function modifView($post_id)
 {
     $post_id = strip_tags($post_id);
     $post_id = intval($post_id);
     $post_id = filter_var($post_id, FILTER_VALIDATE_INT);
     $post = Post::with('category', 'user')->where('post_id', '=', $post_id)->get();
     $action = str_replace(':post_id', $post_id, $this->app->urlFor('post_modif'));
     $cancel = $this->app->urlFor('posts');
     $categories = Category::orderBy('category')->get();
     if (isset($_SESSION['vars'])) {
         unset($_SESSION['vars']);
     }
     $this->view = new PostModif($post, $action, $cancel, $categories);
     $this->view->display();
 }
Example #25
0
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $search = Input::get('search');
         $query->where('title', 'like', "%{$search}%");
         $query->orWhere('content', 'like', "%{$search}%");
         // $query->whereHas('user', function($q){
         // 	$q->where('email', 'like', '%codeup%');
         // });
     }
     $posts = $query->orderBy('created_at', 'desc')->paginate(4);
     $data = array('posts' => $posts);
     return View::make('posts.index')->with($data);
 }
Example #26
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $query->where('title', 'like', '%' . Input::get('search') . '%');
         $query->orWhere('description', 'like', '%' . Input::get('search') . '%');
     }
     if (Request::wantsJson()) {
         $posts = $query->orderBy('created_at', 'desc')->get();
         return Response::json($posts);
     } else {
         $posts = $query->orderBy('created_at', 'desc')->paginate(4);
         return View::make('posts.index', array('posts' => $posts));
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //----> possible chaining of queries with laravel
     // $query = Post::with('user');
     //---> to check if there is a search (use Input::get and put that variable inside of the queries like title 1)
     //if (Input::has('search')) {
     // $query->where('title', 'like', '%title 1');
     // $query->orWhere('body', 'like', '%body 1');
     // whereHas takes in 2 parameters, 1 function name like user, 2 function q
     // $query->orWhereHas('user', function($q){
     // 	$q->where('email','like', '%codeup%');
     // })
     //}
     // $posts = $query->paginate(4);
     $posts = Post::with('user')->paginate(5);
     return View::make('index')->with(['posts' => $posts]);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $postIdOrTitle
  * @return Response
  */
 public function show($postIdOrTitle)
 {
     if (is_numeric($postIdOrTitle)) {
         $post = Post::with('user', 'postType')->where('id', '=', $postIdOrTitle)->first();
         if (!$post) {
             App::abort(404);
             return Redirect::action('PostsController@index');
         }
     } else {
         $post = Post::with('postType')->where('slug_title', '=', $postIdOrTitle)->first();
         if (!$post) {
             App::abort(404);
             return Redirect::action('PostsController@index');
         }
     }
     return View::make('posts.show')->with('post', $post);
 }
Example #29
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     // $posts = Post::with('user')->paginate(4);
     // return View::make('posts.index')->with('posts', $posts);
     if (Input::has('search')) {
         $search = Input::get('search');
         $posts = Post::with('user')->where('title', 'LIKE', "%{$search}%")->orWhere('body', 'LIKE', "%{$search}%")->orderBy('title', 'asc')->paginate(5);
         if ($posts->count() == 0) {
             Session::flash('errorMessage', 'Search not found');
             return Redirect::action('PostsController@index');
         }
         return View::make('posts.index')->with('posts', $posts);
     } else {
         $posts = Post::with('user')->paginate(5);
         return View::make('posts.index')->with('posts', $posts);
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $query = Post::with('user');
     if (Input::has('search')) {
         $search = Input::get('search');
         $query->where('title', 'like', "%{search}")->orWhere('content', 'like', "%{search}%");
     }
     $query->orderBy('created_at', 'desc');
     // gives us back a collection - eloquent collection
     // $posts = Post::all();
     // gives us a a pagination collection:
     // $posts = Post::paginate(4);
     // gives us back a builder collection:
     $posts = Post::with('user')->orderBy('created_at', 'desc')->paginate(3);
     return View::make('posts.index')->with('posts', $posts);
     // ****add search box****
 }