本文整理匯總了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);
}