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


PHP Post::all方法代码示例

本文整理汇总了PHP中app\models\Post::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::all方法的具体用法?PHP Post::all怎么用?PHP Post::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Post的用法示例。


在下文中一共展示了Post::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIndex

 public function testIndex()
 {
     factory(\App\Models\Post::class, 5)->create();
     $postsCount = \App\Models\Post::all()->count();
     // index
     $this->logout()->request('GET', 'api/posts')->assertStatus(200)->assertKeyExists('result.data.0.id')->assertKeyChildrenCountEquals('result.data', $postsCount);
     // @TODO pagination?
 }
开发者ID:xEdelweiss,项目名称:my-perfect-back-end,代码行数:8,代码来源:PostsTest.php

示例2: testModelSeed

 /**
  * Test samples for all models have been seeded.
  */
 public function testModelSeed()
 {
     $message = 'Haven\'t you forgotten to run artisan migrate and db::seed?';
     $this->assertNotEmpty(Author::all(), $message);
     $this->assertNotEmpty(Comment::all(), $message);
     $this->assertNotEmpty(Post::all(), $message);
     $this->assertNotEmpty(Site::all(), $message);
 }
开发者ID:jonpitch,项目名称:limoncello-collins,代码行数:11,代码来源:ModelsAndSeedsTest.php

示例3: run

 public function run()
 {
     DB::table('comments')->delete();
     $posts = Post::all()->lists('id')->toArray();
     for ($i = 0; $i < 50; $i++) {
         Comment::create(['post_id' => $posts[array_rand($posts, 1)], 'name' => 'Annonim', 'comment' => 'My first post', 'published' => true]);
     }
 }
开发者ID:black-bullet,项目名称:laravel-blog,代码行数:8,代码来源:CommentsSeeder.php

示例4: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     $posts = Post::all();
     $response = new \stdClass();
     $response->success = true;
     $response->total = count($posts);
     $response->data = $posts;
     return response()->json($response);
 }
开发者ID:nirebeko,项目名称:EventMap,代码行数:15,代码来源:PostRESTController.php

示例5: testModelSeed

 /**
  * Test samples for all models have been seeded.
  */
 public function testModelSeed()
 {
     $message = 'Haven\'t you forgotten to run artisan migrate and db::seed?';
     $this->assertNotEmpty(Author::all(), $message);
     $this->assertNotEmpty(Comment::all(), $message);
     $this->assertNotEmpty(Post::all(), $message);
     $this->assertNotEmpty(Site::all(), $message);
     $isAuthenticated = Auth::attempt(['email' => UsersTableSeeder::SAMPLE_LOGIN, 'password' => UsersTableSeeder::SAMPLE_PASSWORD]);
     $this->assertTrue($isAuthenticated);
 }
开发者ID:greyexpert,项目名称:limoncello-shot,代码行数:13,代码来源:ModelsAndSeedsTest.php

示例6: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $modelPost = new \App\Models\Post();
     $posts = \App\Models\Post::all(['id']);
     foreach ($posts as $id) {
         for ($i = 0; $i < 10; $i++) {
             factory(\App\Models\Comment::class)->create(['post_id' => $id->id]);
         }
     }
 }
开发者ID:pauloricardo,项目名称:blog-son-laravel,代码行数:15,代码来源:CommentTableSeeder.php

示例7: index

 /**
  * Shows all posts.
  *
  * @return Response
  */
 public function index()
 {
     // Get all the post models
     $posts = Post::all();
     // Retrieve the user, or instantiate a new instance
     $user = User::firstOrCreate(['name' => 'Chris', 'email' => 'cjsimon333@gmail.com', 'password' => 'goteam123']);
     // Login with that user
     Auth::login($user);
     // Render the 'posts' view passing in the $posts as parameter 'posts'
     return View('posts')->with('posts', $posts);
 }
开发者ID:sgelbart,项目名称:Laravel,代码行数:16,代码来源:PostController.php

示例8: galeria

 function galeria()
 {
     $posts = \App\Models\Post::all();
     $tags = \App\Models\Tag::all();
     $tagsUsados = [];
     $tagsTotal = [];
     $contTags = 0;
     $contTagsTotal = 0;
     foreach ($posts as $p) {
         foreach ($p->tags as $t) {
             $tagsUsados[$contTags] = $t->clave;
             $contTags++;
         }
     }
     foreach ($tags as $tag) {
         $tagsTotal[$contTagsTotal] = $tag->clave;
         $contTagsTotal++;
     }
     $tagsUsadosNeto = array_intersect($tagsTotal, $tagsUsados);
     return view('front.galeria')->with(array('posts' => $posts, 'tags' => $tags, 'tt' => $tagsUsadosNeto));
 }
开发者ID:Pacotreflip,项目名称:gci,代码行数:21,代码来源:PostController.php

示例9: function

<?php

Route::get('/', function () {
    // return view('allpost');
});
// ==============  all posts/single posts  ============== //
Route::get('posts', function () {
    $posts = \App\Models\Post::all();
    return view('allpost')->with("posts", $posts);
});
Route::get('posts/{id}', function ($id) {
    $post = \App\Models\Post::find($id);
    return view('post', compact('post'));
});
// ==============  show user/create user  ============== //
Route::get('users/{id}', function ($id) {
    $user = \App\Models\User::find($id);
    return view('user', compact('user'));
});
Route::post('users', function (\App\Http\Requests\CreateUserRequest $request) {
    $user = \App\Models\User::create($request->all());
    $user->password = bcrypt('$user->password');
    $user->save();
    return redirect('users/' . $user->id);
});
// ==============  login/out/signup  ============== //
Route::get('users/create', function ($id) {
    return view('signup');
});
Route::get('login', function () {
    return view('login');
开发者ID:Eben-Hafkamp,项目名称:klarity,代码行数:31,代码来源:routes.php

示例10: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = \App\Models\Post::all();
     return view('allPosts', ['post' => $posts]);
 }
开发者ID:vidin16,项目名称:elizabethj,代码行数:10,代码来源:PostsController.php

示例11: _newestPublished

    }
    public static function _newestPublished($amount)
    {
        return static::_all('is_published = 1 order by created_on desc limit ' . (int) $amount);
    }
    public static function _query()
    {
        return array('tables' => array('posts', 'categories c'), 'fields' => array('c.*', 'posts.*'), 'conditions' => array('c.category_id = posts.category_id'));
    }
}
/**/
Post::event(array('_insert'), function ($self, $args, $chain) {
    if (isset($args->values['title']) && !isset($args->values['original_slug'])) {
        $slug = Output::slugify($args->values['title']);
        //var_dump($slug);
        $slugs = Post::all("original_slug LIKE ?", $slug . '%');
        if ($slugs) {
            $nums = array();
            $slugs = array_map(function ($post) use($slug, &$nums) {
                $nums[] = (int) substr($post->original_slug, strlen($slug) + 1);
                return $post->original_slug;
            }, $slugs);
            rsort($nums, SORT_NUMERIC);
            //print_r($slugs);
            //print_r($nums);
            $slug .= '-' . ($nums[0] + 1);
            //var_dump($slug);
        }
        //exit;
        $args->values['original_slug'] = $slug;
    }
开发者ID:rudiedirkx,项目名称:Rudie-on-wheels,代码行数:31,代码来源:Post.php

示例12: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = \App\Models\Post::all();
     $data = compact('posts');
     return view('posts.posts', $data);
 }
开发者ID:roger791024,项目名称:laravel_blog,代码行数:11,代码来源:PostsController.php

示例13: index

 public function index()
 {
     $postsPerPage = $this->_config('posts_on_index');
     // Way 1
     // Define which get method to use to fetch Posts by checking ACL
     // Use that function and the Model's logic to get those posts.
     $unpub = $this->user->hasAccess('blog read unpublished');
     $method = $unpub ? 'newest' : 'newestPublished';
     $posts = models\Post::$method($postsPerPage);
     // The quick 'n dirty //
     $page = Options::one($_GET, 'page', 1, false);
     $start = ($page - 1) * $postsPerPage;
     $conditions = $unpub ? '1' : 'is_published = 1';
     $posts = models\Post::all($conditions . ' ORDER BY created_on DESC LIMIT ' . $start . ', ' . $postsPerPage . '');
     // Don't do it! //
     // Way 2
     // Define the difference in conditions here (instead of in the Model)
     $conditions = $unpub ? '' : array('is_published' => true);
     $numAllPosts = models\Post::count($conditions);
     // Way 3
     // A third way would be a combination like this:
     /*
     			$access = $this->user->hasAccess('blog read unpublished');
     			$posts = model\Post::postsByAccess($access, $this->_config('posts_on_index'));
     */
     // That way you can check access in the Controller and have fetch logic in the Model
     $messages = Session::messages();
     $canCreatePosts = $this->user->hasAccess('blog create posts');
     return get_defined_vars();
     // view will be rendered by row\Controller->_post_action
     return $this->_display(__METHOD__, get_defined_vars(), !$this->AJAX);
     // view will be rendered by Output->display
     return $this->_display(get_defined_vars());
     // view will be rendered by Output->display
 }
开发者ID:rudiedirkx,项目名称:Rudie-on-wheels,代码行数:35,代码来源:blogController.php

示例14: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $this->checkParametersEmpty();
     return $this->getResponse(Post::all());
 }
开发者ID:resourcemode,项目名称:limoncello-collins,代码行数:10,代码来源:PostsController.php

示例15: index

 public function index()
 {
     $posts = Post::all();
     return $this->response->array($posts);
 }
开发者ID:alaevka,项目名称:angler,代码行数:5,代码来源:PostController.php


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