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


PHP Post::categories方法代码示例

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


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

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create('en_GB');
     $categories = [];
     foreach (range(1, $this->categoriesCount) as $index) {
         $category = new Category();
         $category->name = $faker->word;
         $category->created_at = $faker->dateTime;
         $category->updated_at = $faker->dateTime;
         $category->save();
         $categories[$index] = $category;
     }
     foreach (range(1, $this->postCount) as $index) {
         $post = new Post();
         $post->title = $faker->sentence();
         $post->content = '<p>' . join('</p><p>', $faker->paragraphs()) . '</p>';
         $post->created_at = $faker->dateTime;
         $post->updated_at = $faker->dateTime;
         $post->save();
         foreach (range(1, rand($this->categoriesPerPost[0], $this->categoriesPerPost[1])) as $categoryIndex) {
             $post->categories()->save($categories[rand(1, $this->categoriesCount)]);
         }
     }
 }
开发者ID:xeeeveee,项目名称:Laravel-Transformers-Example,代码行数:29,代码来源:PostSeeder.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = ['published_at' => 'date_format:"Y-m-d H:i:s"', 'categories' => 'array|not_inInArray:1|integerInArray|existsInArray:post_category,id', 'status' => 'in:published,draft,trash', 'visibility' => 'in:public,private', 'tags' => 'array|stringInAarray', 'title' => 'min:1|max:100', 'slug' => 'required|alpha_dash|min:1|max:100', 'content' => ''];
     $validator = Validator::make(Input::only(array_keys($rules)), $rules);
     if ($validator->fails()) {
         throw new ResourceException($validator->errors()->first());
     }
     $post = new Post();
     $fields = ['slug', 'status', 'visibility', 'published_at'];
     foreach ($fields as $key => $field) {
         if (Input::has($field)) {
             $post->{$field} = Input::get($field);
         }
     }
     //field which can null/empty string
     $fields = ['title', 'content'];
     foreach ($fields as $key => $field) {
         if (Input::get($field) === '') {
             $post->{$field} = null;
         } elseif (Input::has($field)) {
             $post->{$field} = Input::get($field);
         }
     }
     $post->save();
     $post->categories()->sync(Input::get('categories', []));
     if (Input::has('tags')) {
         $post->retag(Input::get('tags'));
     }
     return $this->show($post->id);
 }
开发者ID:TolotraRam,项目名称:laravel-angular-cms,代码行数:35,代码来源:PostController.php


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