本文整理汇总了PHP中app\Post::take方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::take方法的具体用法?PHP Post::take怎么用?PHP Post::take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::take方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($slug)
{
$work = Work::where('slug', $slug)->firstOrFail();
$morePosts = Post::take(3)->orderBy("created_at", "desc")->get();
$moreWorks = Work::where('slug', '!=', $work->slug)->take(3)->orderBy("created_at", "desc")->get();
return view('works.show', compact("work", "moreWorks", "morePosts"));
}
示例2: dashboard
/**
* Show the application dashboard screen to the superadmin.
*
* @return Response
*/
public function dashboard()
{
$activeCount = User::where('active', '1')->count();
$subscriberCount = User::where('role', 'subscriber')->count();
$freelancerCount = User::where('role', 'freelancer')->count();
$inactiveCount = User::where('active', '0')->count();
$latestUsers = User::take(4)->latest()->get();
$latestSubscribers = User::take(4)->where('role', 'subscriber')->latest()->get();
$latestPosts = Post::take(4)->latest()->get();
$latestPages = Page::take(4)->latest()->get();
return view('superadmin.dashboard')->with('activeCount', $activeCount)->with('subscriberCount', $subscriberCount)->with('freelancerCount', $freelancerCount)->with('inactiveCount', $inactiveCount)->with('latestUsers', $latestUsers)->with('latestSubscribers', $latestSubscribers)->with('latestPosts', $latestPosts)->with('latestPages', $latestPages);
}
示例3: getPosts
public function getPosts(Request $request)
{
try {
$session_token = $request->get('session_token');
$index = $request->get('index', 1);
$limit = 5;
$offset = $index - 1;
$posts = Post::take($limit)->offset($offset * $limit)->orderBy('created_at', 'DESC')->get();
$data = [];
$customer = SessionUtil::getCustomer($session_token);
$timeAgo = new TimeAgo();
foreach ($posts as $post) {
$is_liked = DB::table('post_likes')->where('customer_id', $customer->id)->where('post_id', $post->id)->exists();
$is_photo_post = $post->photo != null && $post->photo != "";
$data[] = ['id' => $post->id, 'description' => $post->description, 'photo' => $post->photo, 'like_count' => $post->likes->count(), 'is_liked' => $is_liked, 'is_photo_post' => $is_photo_post, 'comment_count' => $post->comments->count(), 'customer_name' => $post->customer->display_name, 'ago' => $timeAgo->inWords($post->created_at)];
}
// sleep(2000);
return Response::json(['status' => 1, 'message' => 'Success', 'data' => $data]);
} catch (Exception $e) {
return Response::json(['status' => 0, 'message' => $e->getMessage()]);
}
}
示例4: index
public function index()
{
$annonces = Post::take(6)->get();
return view('index', compact('annonces'));
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$posts = Post::take(4)->orderBy('id', 'desc')->get();
return view('painel.postagens.postagens', compact('posts'));
}
示例6: index
/**
* Display the homepage content
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = Post::take(5)->orderBy('created_at', 'desc')->get();
$page = Page::where('title', 'home')->first();
return view('welcome', compact('posts', 'page'));
}
示例7: show
/**
* Display the specified resource.
*
* @param \App\Post $Post
* @return Response
*/
public function show(Post $post)
{
$sidebarPosts = Post::take(10)->latest()->get();
// single Post view
return view('posts.show', compact('post'))->with('sidebarPosts', $sidebarPosts);
}