本文整理汇总了PHP中app\models\Post::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::with方法的具体用法?PHP Post::with怎么用?PHP Post::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::with方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($postID)
{
$post = Cache::remember('post_' . $postID, 15, function () use($postID) {
return Post::with('tags')->find($postID);
});
return self::makeResponse($post);
}
示例2: showPost
public function showPost($slug, Request $request)
{
$post = Post::with('tags')->whereSlug($slug)->firstOrFail();
$tag = $request->get('tag');
if ($tag) {
$tag = Tag::whereTag($tag)->firstOrFail();
}
return view($post->layout, compact('post', 'tag'));
}
示例3: getList
public static function getList($count = 10)
{
try {
return Post::with('user')->orderBy('public_date', 'DESC')->paginate($count);
} catch (Exception $e) {
Log::info('Post:getList(): ' . $e->getMessage());
return array();
}
}
示例4: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::with(array('User' => function ($query) {
$query->select('id', 'name');
}))->find($id);
if (!$post) {
return Response::json(['error' => ['message' => 'Post does not exist']], 404);
}
// get previous joke id
$previous = Post::where('id', '<', $post->id)->max('id');
// get next joke id
$next = Post::where('id', '>', $post->id)->min('id');
return Response::json(['previous_joke_id' => $previous, 'next_joke_id' => $next, 'data' => $this->transform($post)], 200);
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return $this->getResponse(Post::with(['author', 'comments', 'author.posts'])->get()->all());
}
示例6: normalIndexData
/**
* Return data for normal index page
*
* @return array
*/
protected function normalIndexData()
{
$posts = Post::with('tags')->where('published_at', '<=', Carbon::now())->where('is_draft', 0)->orderBy('published_at', 'desc')->simplePaginate(config('upload.posts_per_page'));
return ['title' => config('upload.title'), 'subtitle' => config('upload.subtitle'), 'posts' => $posts, 'page_image' => config('upload.page_image'), 'meta_description' => config('upload.description'), 'reverse_direction' => false, 'tag' => null];
}
示例7: index
public function index()
{
$posts = Post::with('categories')->get();
return $this->postTransformer->transformCollection($posts);
}
示例8: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$model = Post::with('tags')->get()->toArray();
return response()->json(['error' => false, 'data' => ['posts' => $model, 'counts' => count($model)]], 200);
}