當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::latest方法代碼示例

本文整理匯總了PHP中app\Post::latest方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::latest方法的具體用法?PHP Post::latest怎麽用?PHP Post::latest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Post的用法示例。


在下文中一共展示了Post::latest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 public function index()
 {
     //        $posts = Post::all();
     //        $posts = Post::orderBy('created_at', 'desc')->get();
     $posts = Post::latest('created_at')->get();
     dd($posts->toArray());
     return view('posts.index');
 }
開發者ID:YumaKimura,項目名稱:practiceblog,代碼行數:8,代碼來源:PostsController.php

示例2: index

 public function index()
 {
     $page_title = 'This is HomePage';
     $posts = Post::latest('published_at')->published()->get();
     $posts = Post::paginate(5);
     //dd($posts);
     return view('posts.index', compact('page_title', 'posts'));
 }
開發者ID:shawon922,項目名稱:blog,代碼行數:8,代碼來源:PostsController.php

示例3: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $limit = Input::get('limit') ?: 5;
     $posts = Post::latest('published_at')->paginate($limit);
     //        dd(get_class_methods($posts));
     return $this->respond(['data' => $this->postTransformer->transformCollection($posts->all()), 'paginator' => ['total_count' => $posts->total(), 'current_page' => $posts->currentPage(), 'total_pages' => ceil($posts->total() / $posts->perPage()), 'limit' => $posts->perPage()]]);
 }
開發者ID:lyz1990,項目名稱:LaraVueBlog,代碼行數:13,代碼來源:PostsController.php

示例4: index

 public function index($profile = null)
 {
     if ($profile != null) {
         $posts = $profile->posts()->latest()->paginate(20);
     } else {
         $posts = Post::latest()->paginate(20);
     }
     return view('admin.post.index', compact('posts', 'profile'))->with(['title' => 'Post Management']);
 }
開發者ID:emadmrz,項目名稱:Hawk,代碼行數:9,代碼來源:PostManagementController.php

示例5: index

 function index()
 {
     $user = Auth::user();
     $posts = Post::latest('id')->get();
     $companies = Company::all();
     $users = User::all();
     $testvar = "XYZABC";
     return view('users.test', compact('testvar'));
     return view('users.index', compact('user', 'posts', 'companies', 'users'));
 }
開發者ID:Kishimotovn,項目名稱:IMS_Laravel,代碼行數:10,代碼來源:UserController.php

示例6: index

 public function index()
 {
     // $posts = \App\Post::all();
     // $posts = Post::all();
     // $posts = Post::orderBy('created_at', 'desc')->get();
     $posts = Post::latest('created_at')->get();
     // dd($posts->toArray()); // dump to die
     // $posts = [];
     // return view('posts.index', ['posts' => $posts]);
     return view('posts.index')->with('posts', $posts);
 }
開發者ID:hirolog,項目名稱:dotinstall_laravel5,代碼行數:11,代碼來源:PostsController.php

示例7: index

 public function index()
 {
     $latestArticles = Article::latest()->take(6)->get();
     $latestPosts = Post::latest()->take(6)->get();
     $latestProblems = Problem::latest()->take(6)->get();
     $latestGroups = Group::latest()->take(6)->get();
     $latestUsers = User::latest()->take(6)->get();
     $ratedUsers = User::orderBy('rate', 'desc')->take(6)->get();
     $chartDatas = Comment::select([DB::raw('DATE(created_at) AS date'), DB::raw('COUNT(id) AS count')])->groupBy('date')->orderBy('date', 'ASC')->get()->toArray();
     return view('admin.dashboard.index', compact('latestArticles', 'latestPosts', 'latestProblems', 'latestGroups', 'latestUsers', 'ratedUsers', 'chartDatas'))->with(['title' => 'Admin Dashboard Panel']);
 }
開發者ID:emadmrz,項目名稱:Hawk,代碼行數:11,代碼來源:DashboardController.php

示例8: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     view()->composer(['includes.footer.mainfooter', 'includes.snellepage'], function ($view) {
         $view->with('diensten', Dienst::all());
     });
     view()->composer('includes.personen', function ($view) {
         $view->with('users', User::where('role_id', '1')->take(3)->get());
     });
     view()->composer('includes.recensies.klanten', function ($view) {
         $view->with('recensies', Recensie::where('uitgelicht', '1')->get());
     });
     view()->composer('includes.sidebar.groot', function ($view) {
         $view->with('posts', Post::latest('published_at')->published()->get()->take(5));
     });
 }
開發者ID:jeroenhekihenk,項目名稱:video-platform,代碼行數:20,代碼來源:AppServiceProvider.php

示例9: getIndex

 public function getIndex()
 {
     if (Auth::check()) {
         $posts = Post::latest()->get();
         foreach ($posts as $key => $value) {
             if (!Auth::user()->subdoots->contains($value->subdoot->id)) {
                 unset($posts[$key]);
             }
         }
     } else {
         $posts = Post::latest()->get();
     }
     $filter = "new";
     return view('index', compact('filter', 'posts'));
 }
開發者ID:nehero,項目名稱:updoot,代碼行數:15,代碼來源:PagesController.php

示例10: team

 public function team()
 {
     $lastSliders = Slider::latest()->take(1)->get();
     $lastPosts = Post::latest()->take(2)->get();
     $lastEvents = Event::latest()->take(2)->get();
     $title = 'Equipo';
     $lastEvents2 = Event::latest()->skip(2)->take(2)->get();
     return view('guest.team')->with('title', $title)->with('lastPosts', $lastPosts)->with('lastEvents', $lastEvents)->with('lastEvents2', $lastEvents2)->with('lastSliders', $lastSliders);
 }
開發者ID:Zizazao,項目名稱:evolutizalocal,代碼行數:9,代碼來源:guestController.php

示例11: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $post_all = Post::latest()->published()->paginate(5);
     //get one to many
     $post = Post::find(11);
     if ($post) {
         $comments = $post->comments()->get();
     }
     //$comments->posts()->where('active', 1)->get();
     //$comments = Post::find(11)->comments()->where('title', 'foo')->first();
     //inverse
     $comment = Comment::find(1);
     if ($comment) {
         $post_found = $comment->post->title;
     }
     //many to many
     $user = User::find(32);
     if ($user) {
         $roles = $user->roles;
     }
     //$roles2 = User::find(11)->roles()->orderBy('role')->get();
     //Has Many Through
     $country = Country::find(1);
     $post_by_country = $country->posts;
     //Polymorphic
     //foreach ($post->likes as $like) {}
     //inverse
     $like = Like::find(1);
     if ($like) {
         $likeable = $like->likeable;
     }
     //Many To Many Polymorphic
     //$post = App\Post::find(1);
     //foreach ($post->tags as $tag) {}
     //inverse
     $tag = Tag::find(1);
     //Querying Relationship Existence
     // Retrieve all posts that have at least one comment...
     //$posts = Post::has('comments')->get();
     // Retrieve all posts that have three or more comments...
     $posts = Post::has('comments', '>=', 3)->get();
     // Retrieve all posts that have at least one comment with votes...
     //$posts = Post::has('comments.votes')->get();
     // Retrieve all posts with at least one comment containing words like foo%
     // $posts = Post::whereHas('comments', function ($query) {//orWhereHas
     //     $query->where('content', 'like', 'foo%');
     // })->get();
     //Eager loading
     $post2 = Post::with('user')->get();
     //Eager Loading Multiple Relationships
     //Sometimes you may need to eager load several different relationships in a single operation. To do so, just pass additional arguments to the with method:
     //$books = Post::with('user', 'publisher')->get();
     //Nested Eager Loading
     //To eager load nested relationships, you may use "dot" syntax. For example, let's eager load all of the book's authors and all of the author's personal contacts in one Eloquent statement:
     //$books = App\Book::with('author.contacts')->get();
     //Constraining Eager Loads
     //Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:
     // $users = App\User::with(['posts' => function ($query) {
     //     $query->where('title', 'like', '%first%');
     // }])->get();
     //In this example, Eloquent will only eager load posts that if the post's title column contains the word first. Of course, you may call other query builder to further customize the eager loading operation:
     // $users = App\User::with(['posts' => function ($query) {
     //     $query->orderBy('created_at', 'desc');
     // }])->get();
     //Lazy Eager Loading
     //Sometimes you may need to eager load a relationship after the parent model has already been retrieved. For example, this may be useful if you need to dynamically decide whether to load related models:
     //$books = App\Book::all();
     // if ($someCondition) {
     //     $books->load('author', 'publisher');
     // }
     //If you need to set additional query constraints on the eager loading query, you may pass a Closure to the load method:
     // $books->load(['author' => function ($query) {
     //     $query->orderBy('published_date', 'asc');
     // }]);
     return view('posts.index', compact('post', 'comments', 'post_found', 'user', 'roles', 'roles2', 'country', 'post_by_country', 'likeable', 'tag', 'post2', 'post_all'));
 }
開發者ID:TraianAlex,項目名稱:laravel4,代碼行數:81,代碼來源:PostController.php

示例12: index

 public function index()
 {
     $posts = Post::latest()->paginate(20);
     return view("backend.post.index", ["posts" => $posts]);
 }
開發者ID:erayaydin,項目名稱:erayaydin,代碼行數:5,代碼來源:PostController.php

示例13: postsAuth

 /**
  * Display a listing of the auth resource.
  *
  * @return Response
  */
 public function postsAuth()
 {
     $limit = Input::get('limit') ?: 2;
     $posts = Post::latest('updated_at')->where('user_id', '=', Auth::user()->id)->paginate($limit);
     return view('posts.postsAuth', compact('posts'));
 }
開發者ID:grigoremihaela,項目名稱:myfirstlaravel,代碼行數:11,代碼來源:PostsController.php

示例14: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     return Post::latest()->paginate(10);
 }
開發者ID:nickdunn2,項目名稱:bitter,代碼行數:9,代碼來源:PostsController.php

示例15: get

 public function get($count = 10)
 {
     return Post::latest()->paginate($count);
 }
開發者ID:bastienbot,項目名稱:wordpresskilled.me,代碼行數:4,代碼來源:PaginatedPosts.php


注:本文中的app\Post::latest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。