本文整理汇总了PHP中Post::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::with方法的具体用法?PHP Post::with怎么用?PHP Post::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* GET /posts
* Get a listing of all posts.
*
* @return Response
*/
public function index()
{
$posts = $this->post->with('tags', 'series')->published()->latest()->paginate(10);
$page = Input::get('page');
$title = $page ? "All posts (Page {$page})" : 'All posts';
return View::make('posts.index', compact('posts'))->withTitle($title);
}
示例2: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$post = Post::where('id', '=', $id)->first();
$answer = Post::where('id', '=', $post->accepted_answer_id)->first();
$answers = Post::with(array('votes'))->where('parent_id', '=', $post->id)->where('id', "<>", $post->accepted_answer_id)->get();
$tags = Tag::all();
$data = array('post' => $post, 'answer' => $answer, 'answers' => $answers, 'tags' => $tags);
return View::make('public.question.index', $data);
}
示例3: getByCategory
/**
* Display posts by category
*/
public function getByCategory($category = 'all')
{
if ($category == 'all') {
$posts = Post::with('user')->orderBy('id', 'desc')->paginate(15);
} else {
$posts = Post::with('user')->where('category', $category)->orderBy('id', 'desc')->paginate(15);
}
return View::make('posts.index')->with(['posts' => $posts, 'category' => $category]);
}
示例4: postsApi
public function postsApi()
{
$posts = \Post::with(['user' => function ($query) {
// getting the ID field is necessary
$query->select(['id', 'username']);
// user_id is required to enable eager loading
}])->get(['id', 'title', 'status', 'user_id']);
return \Response::json($posts);
}
示例5: index
public function index()
{
// hard-coding autologin of User #2,
// so we don't have to implement Auth for the scope of this demo.
$user = User::find(2);
Auth::login($user);
// get recent posts, and eager load texts
$posts = Post::with('text')->orderBy('created_at', 'desc')->get();
$this->layout->content = View::make('home')->with('posts', $posts);
}
示例6: show
public function show($id)
{
$user = User::find($id);
$posts = Post::with('user')->where('user_id', $id)->orderBy('created_at', 'desc')->paginate(4);
if ($user != null) {
return View::make('showuser')->with('user', $user)->with('posts', $posts);
} else {
App::abort(404);
}
}
示例7: index
public function index()
{
// Eloquent collection
// $posts = Post::all();
$posts = Post::with('user')->paginate(2);
// Pagination collection
// $perPage = Input::get('per-page'); you then pass $perpage into the paginate
// $posts = Post::paginate(2);
return View::make('posts.index')->with(array('posts' => $posts));
}
示例8: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$query = Post::with('user');
if (Input::has('search')) {
$query->where('title', 'like', '%' . Input::get('search') . '%');
$query->orWhere('body', 'like', '%' . Input::get('search') . '%');
}
$posts = $query->orderBy('id', 'desc')->paginate(14);
return View::make('posts.index')->with('posts', $posts);
}
示例9: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
$router->bind('post', function ($value) {
return Post::with('user')->where('slug', $value)->first();
});
$router->bind('comment', function ($value) {
return Comment::with('user')->where('id', $value)->first();
});
}
示例10: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
if (Auth::id() != $id) {
Log::info('This user id is not equal');
return Redirect::action('UsersController@show', Auth::id());
}
$post = Post::with('user')->get();
$user = User::find($id);
return View::make('users.edit', compact('user'));
}
示例11: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$query = Post::with('user');
if (Input::has('search')) {
$search = Input::get('search');
$query->where('title', 'like', "%{$search}%")->orWhere('body', 'like', "%{$search}%");
}
$posts = $query->orderBy('created_at', 'desc')->paginate(5);
return View::make('posts.index')->with('posts', $posts);
}
示例12: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
// $posts = Post::paginate(4);
// $data = array(
// 'posts'=> $posts
// );
// return View::make('posts.index')->with($data);
$posts = Post::with('user')->orderBy('created_at', 'desc')->paginate(4);
return View::make('posts.index')->with('posts', $posts);
}
示例13: blog
public function blog($page = 1)
{
$limit = 5;
$offset = ($page - 1) * $limit;
$posts = Post::take($limit)->skip($offset)->active()->orderBy('created_at', 'desc')->get();
Paginator::setBaseUrl(Config::get('app.url') . '/blog');
Paginator::setCurrentPage($page);
$totalItems = Post::with('id')->active()->count();
$paginator = PrettyPaginator::make($posts->toArray(), $totalItems, $limit);
return View::make('blog.blog', ['posts' => $posts, 'paginate' => $paginator]);
}
示例14: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$search = Input::get('search');
if ($search) {
$query = Post::with('user')->where('title', 'LIKE', '%' . $search . '%')->orWhere('body', 'LIKE', '%' . $search . '%')->orWhere('location', 'LIKE', '%' . $search . '%');
} else {
$query = Post::with('user');
}
$posts = $query->orderBy('created_at', 'desc')->paginate(30);
return View::make('posts.index')->with(['posts' => $posts, 'search' => $search]);
}
示例15: search
public function search()
{
$search = Input::get('search');
$searchTerms = explode(' ', $search);
$queryPost = Post::with('user');
foreach ($searchTerms as $term) {
$queryPost->where('title', 'LIKE', '%' . $term . '%')->orWhere('content', 'LIKE', '%' . $term . '%');
}
$posts = $queryPost->orderBy('created_at', 'desc')->get();
$tags = Tag::with('posts')->paginate(8);
return View::make('search', compact('posts', 'tags'));
}