当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::with方法代码示例

本文整理汇总了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);
 }
开发者ID:riehlemt,项目名称:neontsunami,代码行数:13,代码来源:PostsController.php

示例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);
 }
开发者ID:UnderDogg,项目名称:StackOverflow-Clone,代码行数:15,代码来源:QuestionController.php

示例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]);
 }
开发者ID:jjong7985,项目名称:laravel.co.kr,代码行数:12,代码来源:PostController.php

示例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);
 }
开发者ID:pogliozzy,项目名称:larabase,代码行数:9,代码来源:PostsController.php

示例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);
 }
开发者ID:shruti222patel,项目名称:laravel-model-demo,代码行数:10,代码来源:HomeController.php

示例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);
     }
 }
开发者ID:Rwilkins1,项目名称:laravel_blog,代码行数:10,代码来源:UsersController.php

示例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));
 }
开发者ID:Reni789,项目名称:blog.dev,代码行数:10,代码来源:PostsController.php

示例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);
 }
开发者ID:anthony87burns,项目名称:blog.dev,代码行数:15,代码来源:PostsController.php

示例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();
     });
 }
开发者ID:adiachenko,项目名称:catchy_api,代码行数:16,代码来源:RouteServiceProvider.php

示例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'));
 }
开发者ID:pascalallen,项目名称:blog.dev,代码行数:16,代码来源:UsersController.php

示例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);
 }
开发者ID:ryanorsinger,项目名称:blog_example,代码行数:15,代码来源:PostsController.php

示例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);
 }
开发者ID:rogerchin,项目名称:blog.dev,代码行数:15,代码来源:PostsController.php

示例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]);
 }
开发者ID:Rotron,项目名称:shop,代码行数:11,代码来源:BlogController.php

示例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]);
 }
开发者ID:pascalallen,项目名称:blog.dev,代码行数:16,代码来源:PostsController.php

示例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'));
 }
开发者ID:mkwarren21,项目名称:blog.dev,代码行数:12,代码来源:HomeController.php


注:本文中的Post::with方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。