示例#1
0
文件: Post.php 项目: lembarek/blog
 /**
  * return all categories that this post
  * do not belongs to.
  *
  * @return Category
  */
 public function CategoriesNotIn()
 {
     $category_ids = $this->categories->map(function ($category) {
         return $category->id;
     });
     return Category::whereNotIn('id', $category_ids)->get();
 }
示例#2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $posts = Post::all();
     $categories = Category::all();
     foreach ($categories as $category) {
         $subPosts = $posts->take(3);
         foreach ($subPosts as $post) {
             $post->addToCategory($category);
         }
     }
 }