/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::orderBy('date_start', 'DESC')->get(); $postPublish = Post::countAllPostsPublished()->get(); $postUnpublish = Post::countAllPostsUnpublished()->get(); return view('post.index', compact('posts', 'postPublish', 'postUnpublish')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $hashtag = $this->argument('hashtag'); $GetterClass = '\\App\\Getters\\' . $this->argument('provider') . 'Getter'; $TransformerClass = 'App\\Transformers\\' . $this->argument('provider') . 'Transformer'; $getter = new $GetterClass(); $this->info('Getting posts from ' . $this->argument('provider')); $posts = $getter->getList($this->argument('howmany'), $this->argument('hashtag')); // transform posts foreach ($posts as $key => $post) { $transformer = new $TransformerClass($post); $currentPost = $transformer->get(); // store if it doesn't already exist if (!Post::has($currentPost['post_id'])) { // check if post is popular enough if ($this->argument('qualityThreshold')) { if ($transformer->isPopular($this->argument('qualityThreshold'))) { Post::create($currentPost); } } else { Post::create($currentPost); } } } // Cache last 50 posts $this->comment('Caching last fifty posts'); $lastFiftyPosts = \App\Post::orderBy('date_published', 'DESC')->take(50)->get(); Cache::put('lastFiftyPosts', $lastFiftyPosts, 5); }
public function getIndex() { $posts = Post::orderBy('created_at', 'desc')->take(5)->get(); $products = Product::orderBy('created_at', 'desc')->take(5)->get(); $references = Reference::orderBy('created_at', 'desc')->take(5)->get(); return view('admin/index', ['posts' => $posts, 'products' => $products, 'references' => $references]); }
public function index() { $posts = Post::orderBy('page_view', 'DESC')->get(); $pageType = 'Random'; $data = compact('posts', 'pageType'); return view('posts.index', $data); }
public function index() { $postType = '文章總覽'; $posts = \App\Post::orderBy('created_at', 'desc')->paginate(5); $data = compact('postType', 'posts'); return view('posts.index', $data); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $posts = Post::orderBy('created_at', 'desc')->paginate(6, ['*'], 'p'); $comments = Comment::all(); $data = ['comments' => $comments, 'posts' => $posts]; return view('posts.index', $data); }
public function feed() { $feed = Feed::make(); // cache the feed for 60 minutes (second parameter is optional) $feed->setCache(60, 'laravelFeedKey'); // check if there is cached feed and build new only if is not if (!$feed->isCached()) { // creating rss feed with our most recent 20 posts $posts = Post::orderBy('created_at')->take(20)->get(); // set your feed's title, description, link, pubdate and language //FIXME: These are duplicated $feed->title = config('seotools.meta.defaults.title'); $feed->description = config('seotools.meta.defaults.description'); $feed->logo = 'http://yoursite.tld/logo.jpg'; $feed->link = route('feed'); $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' $feed->pubdate = $posts[0]->created_at; $feed->lang = 'en'; $feed->setShortening(true); // true or false $feed->setTextLimit(200); // maximum length of description text foreach ($posts as $post) { // set item's title, author, url, pubdate, description and content $image = null; if ($post->coverImage) { $image = ['url' => url($post->coverImage), 'type' => 'image/jpeg']; } $feed->add($post->title, 'Jesse Collis', $post->url(), $post->created_at, $post->subtitle, $post->body, $image); } } return $feed->render('atom'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $posts = Post::all(); // $data = ['posts' => $posts,]; // 自動分頁 $posts = Post::orderBy('created_at', 'desc')->paginate(5); $data = compact('posts'); return view('posts.index', $data); }
public function index() { /* return view('admin.post.index') ->withPosts(Post::all());*/ $posts = Post::orderBy('published_at', 'desc')->paginate(config('blog.posts_per_page')); //分页配置 return view('admin.post.index', compact('posts')); //分页 }
public function index() { if (Input::has('group_id')) { $posts = Post::where('group_id', Input::get('group_id'))->paginate(10)->toArray(); } else { $posts = Post::orderBy('id', 'desc')->paginate(10)->toArray(); } return view('admin.posts.index', compact('posts')); }
/** * Display a listing of the resource. * * @return Response */ public function index() { if (Auth::check()) { $skip = Input::get('p') * 10; $posts = Post::orderBy('points', 'desc')->take(10)->skip($skip)->get(); return view('newsfeed', ['posts' => $posts]); } else { return view('splash', ['submitted' => FALSE]); } }
public static function updateSideBarCache() { $categories = Category::all(); $posts = Post::orderBy('updated_at', 'desc')->limit(2)->get(); if (Cache::has('categories') || Cache::has('posts')) { Cache::flush(); } Cache::forever('posts', compact('posts')); Cache::forever('categories', compact('categories')); }
public function index() { if (Auth::user()->admin) { $posts = Post::orderBy('created_at', 'desc')->get(); return view('admin.index', ['posts' => $posts]); } else { $posts = Post::where('autor_id', Auth::user()->id)->orderBy('created_at', 'desc')->get(); return view('autor.index', ['posts' => $posts]); } }
/** * Display a listing of the resource. * * @param Request $request * @return \Illuminate\Http\Response */ public function index(Request $request) { $search = $request->get("search"); if (!empty($search)) { $posts = Post::where('name', 'Like', '%' . $search . '%')->orderBy('created_at', 'DESC')->paginate(3); } else { $posts = Post::orderBy('created_at', 'DESC')->paginate(3); } return view("posts.index", compact("posts")); }
/** * Display a listing of the resource. * * @return Response */ public function index($category_id = null) { // if a category was passed, use that // if no category, get all posts // if ($category_id) { // $posts = Post::where('category_id', $category_id); // } // else { $posts = Post::orderBy('created_at', 'DESC')->paginate(15); // } return view('posts.index', ['posts' => $posts]); }
public function getSnippets() { $posts = Post::orderBy('created_at', 'desc')->take(self::NUMBER_OF_SNIPPETS)->get(); foreach ($posts as $post) { $post->body = self::shorten_string($post->body, 40); Date::setLocale('de'); $dt = new Date("" . $post->created_at . ""); $dt = $dt->format('j F Y'); $post->loc_date = $dt; $post->url = implode("-", explode(" ", $post->title)); } return view('blog/index', ['posts' => $posts]); }
/** * @return View */ function index() { $colors = ['redback', 'blueback', 'whiteback', 'blackback', 'whiteback']; if (Auth::guest()) { $posts = Post::where('publish_at', '<', Carbon::now())->orderBy('created_at', 'desc')->paginate(5); } else { $posts = Post::orderBy('created_at', 'desc')->paginate(5); } $authors = []; foreach ($posts as $post) { $authors[$post->id] = User::find($post->user_id)->name; } return View('pages.blog.posts', compact('posts', 'authors', 'colors')); }
/** *获取热门帖子 * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $limit = $request->input('limit'); $skip = $request->input('skip'); if (Auth::check()) { $limit = $limit == null ? 20 : $limit; $skip = $skip == null ? 0 : $skip; } else { $limit = 10; $skip = 1; } $hotPosts = Post::orderBy('last_comment_at', 'desc')->skip($skip)->take($limit)->get(); return response()->json(['errno' => 0, 'msg' => 'succes', 'hotSum' => $hotPosts->count(), 'posts' => $hotPosts]); }
/** * 跳转相应的月份归档页 * * @param int $year * @param int $month */ public function date($year, $month) { $time = $year . "-" . $month; $posts = Post::orderBy('created_at', 'desc')->where('is_draft', '==', 0)->get(); $i = 0; $result = array([]); foreach ($posts as $post) { if (substr($post["created_at"], 0, 7) == $time) { $result[$i] = $post; $i++; } $post->content = EndaEditor::MarkDecode($post->content); } return view('blog.archive')->withPosts($result); }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { $user = Auth::user(); $posts = Post::where('user_id', $user->id)->orderBy('created_at', 'desc')->take(6)->get(); $rwposts = Post::orderBy('created_at', 'desc')->take(6)->get(); $charts = User::all(); $chartmembre = User::where('right_id', '1')->get(); $chartauteur = User::where('right_id', '2')->get(); $chartmodo = User::where('right_id', '3')->get(); $chartadmin = User::where('right_id', '4')->get(); $chartslast = User::orderBy('created_at', 'desc')->take(4)->get(); $usersdev = User::where('job_id', '1')->get(); $usersdesign = User::where('job_id', '2')->get(); $userscm = User::where('job_id', '3')->get(); $userswm = User::where('job_id', '4')->get(); $usersinte = User::where('job_id', '5')->get(); $usersref = User::where('job_id', '6')->get(); return view('admin.home', compact('user', 'posts', 'charts', 'chartmembre', 'rwposts', 'chartauteur', 'chartmodo', 'chartadmin', 'chartslast', 'usersdev', 'usersdesign', 'userscm', 'userswm', 'usersinte', 'usersref')); }
/** * Display a listing of the resource. * * @return Response */ public function staffIndex() { // $staff_options = Staff::select('Id', DB::raw('CONCAT(first_name, " ", last_name) AS full_name'))->orderBy('first_name')->lists('full_name', 'Id'); $print = Input::get('print'); $staff_id = Input::get('staff_id'); if ($staff_id) { $staff = Staff::find($staff_id); $posts = $staff->posts; $media_mention = $staff->posts->sum('media_mention'); $presentation = $staff->posts->sum('presentation'); $meeting = $staff->posts->sum('meeting'); $testimonial = $staff->posts->sum('testimonial'); $sponsored_event = $staff->posts->sum('sponsored_event'); $on_campus_collaboration = $staff->posts->sum('on_campus_collaboration'); $off_campus_collaboration = $staff->posts->sum('off_campus_collaboration'); $achievement = $staff->posts->sum('achievement'); $satifaction_survey = $staff->posts->sum('satifaction_survey'); $other = $staff->posts->sum('other'); $total = $staff->posts->count(); $today = Carbon::now(); } else { $posts = Post::orderBy('created_at', 'DESC')->get(); $media_mention = DB::table('posts')->sum('media_mention'); $presentation = DB::table('posts')->sum('presentation'); $meeting = DB::table('posts')->sum('meeting'); $testimonial = DB::table('posts')->sum('testimonial'); $sponsored_event = DB::table('posts')->sum('sponsored_event'); $on_campus_collaboration = DB::table('posts')->sum('on_campus_collaboration'); $off_campus_collaboration = DB::table('posts')->sum('off_campus_collaboration'); $achievement = DB::table('posts')->sum('achievement'); $satifaction_survey = DB::table('posts')->sum('satifaction_survey'); $other = DB::table('posts')->sum('other'); $total = DB::table('posts')->count(); $today = Carbon::now(); } if ($print) { return view('print', compact('posts', 'total', 'media_mention', 'presentation', 'meeting', 'testimonial', 'sponsored_event', 'on_campus_collaboration', 'off_campus_collaboration', 'achievement', 'satifaction_survey', 'other', 'today')); } return view('posts.report_staff', compact('staff_options', 'staff_id', 'posts', 'total', 'media_mention', 'presentation', 'meeting', 'testimonial', 'sponsored_event', 'on_campus_collaboration', 'off_campus_collaboration', 'achievement', 'satifaction_survey', 'other', 'today')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $firstPost = Post::orderBy('post_id', 'asc')->first()->pluck('created_at'); $trackTime = clone $firstPost; $nowTime = Carbon::now()->minute(0)->second(0)->timestamp; $boards = Board::all(); $this->comment("Reviewing all records."); while ($firstPost->timestamp < $nowTime) { $firstPost = $firstPost->addHour(); $hourCount = 0; foreach ($boards as $board) { if ($board->posts_total > 0) { $newRows = $board->createStatsSnapshot($firstPost); $hourCount += count($newRows); } } if ($hourCount > 0) { $this->comment("\tAdded {$hourCount} new stat row(s) from " . $firstPost->diffForHumans()); } } }
/** * Show index Frontend page * @return Response */ public function postsPaginate() { $posts = Post::orderBy('created_at', 'desc')->where('private', '!=', '1')->paginate(5); // count of all comment for Posts $comPostCountQuery = DB::table('comments')->select('post_id', DB::raw('COUNT(*) as comments_count'))->groupBy('post_id')->take(2000)->get(); // check if $comPostCountQuery contain any data if (count($comPostCountQuery, COUNT_RECURSIVE) > 0) { // if jes foreach ($comPostCountQuery as $value) { $ckey[] = $value->post_id; $cval[] = $value->comments_count; } // create array key= post_id value=count of comments $comPostCount = array_combine($ckey, $cval); } else { // if yes $comPostCount = ['0' => '0']; } $newsUsers = User::orderBy('id')->pluck('name', 'id'); return view('frontend.postsPaginate', compact('posts', 'newsUsers', 'comPostCount')); }
private function ordenacaoIndexacao(Request $request) { //Pega os dados da pesquisa (caso exista) $query = $request->get('q'); $coluna = $request->get('c') ? $request->get('c') : 'Nome'; //$coluna = variável da pesquisa. Caso não exista, padrão = 'Nome' //variáveis de ordenação da tabela (vêm do arquivo crud.blade.php) $colunaOrdenacao = $request->get('col') ? $request->get('col') : 'id'; //padrão = id $ascDesc = $request->get('ascDesc') ? $request->get('ascDesc') : 'desc'; //padrão = desc //Verifica se existe algum dado de pesquisa. Caso exista, realizar a pesquisa filtrando os dados //Caso não exista, me dê todos os clientes $registros = $query ? Post::where($coluna, 'LIKE', "%{$query}%")->orderBy($colunaOrdenacao, $ascDesc)->paginate(10) : ($registros = Post::orderBy($colunaOrdenacao, $ascDesc)->paginate(10)); /* Esta parte de baixo é utilizada apenas para facilitar o trabalho na hora de realizar um CRUD */ //Array que possui todos os atributos da classe "Cliente", será passada para a view para criar o CRUD de forma fácil $atributosOld = array(); //Pega um registro do banco de dados para conseguir os atributos de cliente $registro = Post::get()->first()->toArray(); //Coloca os atributos no array correto ($atributos) foreach ($registro as $atributo => $dado) { array_push($atributosOld, ucfirst($atributo)); } //retira os 2 últimos atributos (created_at, updated_at, horario) for ($i = 0; $i < 2; $i++) { array_pop($atributosOld); } //Problema: Utilizando o array_push, o index de cada posição do array será 0, 1, 2, 3... //Não podemos deixar assim, pois o array deve ser indexado da seguinte forma: [id] => [id], [nome] => [nome]... //Isso porque o select (combobox), localizado em crud.blade.php, pega o índice do vetor e joga na variável $coluna. //Perceba que se o índice for 0, 1, 2.. a query ficaria where(0, 'like', query) //Solução: Criar outro array e indexar da maneira correta $atributos = array(); foreach ($atributosOld as $indice => $valorAtributo) { $atributos[$valorAtributo] = $valorAtributo; } return array('registros' => $registros, 'query' => $query, 'coluna' => $coluna, 'atributos' => $atributos, 'ascDesc' => $ascDesc, 'colunaOrdenacao' => $colunaOrdenacao); }
/** * Execute the console command. * * @return mixed */ public function handle() { $firstPost = Post::orderBy('post_id', 'asc')->first()->pluck('created_at'); $nowTime = Carbon::now()->minute(0)->second(0)->timestamp; $boards = Board::all(); $this->comment("Reviewing all records."); while ($firstPost->timestamp < $nowTime) { $firstPost = $firstPost->addHour(); $hourCount = 0; foreach ($boards as $board) { if ($board->posts_total > 0) { $newRows = $board->createStatsSnapshot($firstPost); $hourCount += $newRows->count(); } } if ($hourCount > 0) { $this->comment("\tAdded {$hourCount} new stat row(s) from " . $firstPost->diffForHumans()); } } // Drop boardlist cache. Cache::forget('site.boardlist'); // Generate boardlist again. Board::getBoardsForBoardlist(); }
/** * Run the migrations. * * @return void */ public function up() { Schema::dropIfExists('stats_uniques'); Schema::dropIfExists('stats'); Schema::create('stats', function (Blueprint $table) { $table->bigIncrements('stats_id'); $table->string('board_uri', 32); $table->timestamp('stats_time'); $table->string('stats_type', 25); $table->bigInteger('counter')->unsigned()->default(0); $table->unique(['stats_time', 'board_uri', 'stats_type']); }); Schema::create('stats_uniques', function (Blueprint $table) { $table->bigIncrements('stats_bit_id'); $table->bigInteger('stats_id')->unsigned(); $table->bigInteger('unique'); $table->foreign('stats_id')->references('stats_id')->on('stats')->onDelete('cascade')->onUpdate('cascade'); }); $firstPost = Post::orderBy('post_id', 'asc')->first()->pluck('created_at'); $trackTime = clone $firstPost; $nowTime = \Carbon\Carbon::now()->minute(0)->second(0)->timestamp; $boards = Board::all(); while ($firstPost->timestamp < $nowTime) { $firstPost = $firstPost->addHour(); $hourCount = 0; foreach ($boards as $board) { if ($board->posts_total > 0) { $newRows = $board->createStatsSnapshot($firstPost); $hourCount += count($newRows); } } if ($hourCount > 0) { echo "\tAdded {$hourCount} new stat row(s) from " . $firstPost->diffForHumans() . "\n"; } } }
public function index() { $posts = Post::orderBy('created_at', 'desc')->get(); return view('administration.index', ['posts' => $posts]); }
public function index() { return view("frontend.post.index", ["posts" => Post::orderBy("created_at", "DESC")->paginate(5)]); }
public function index() { $posts = Post::orderBy('created_at', 'desc')->paginate(3); return view('posts.index', ['posts' => $posts]); }
public function show() { $posts = Post::orderBy('published_at', 'desc')->where('status', 'published')->with('category', 'comments')->paginate(10); return view('home.index', compact('posts')); }