本文整理汇总了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');
}
示例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'));
}
示例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()]]);
}
示例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']);
}
示例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'));
}
示例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);
}
示例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']);
}
示例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));
});
}
示例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'));
}
示例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);
}
示例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'));
}
示例12: index
public function index()
{
$posts = Post::latest()->paginate(20);
return view("backend.post.index", ["posts" => $posts]);
}
示例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'));
}
示例14: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return Post::latest()->paginate(10);
}
示例15: get
public function get($count = 10)
{
return Post::latest()->paginate($count);
}