コード例 #1
0
ファイル: PostsController.php プロジェクト: rakeen/creative
 /**
  * @param Post $post
  * @return \Illuminate\View\View
  */
 public function show(Post $post)
 {
     $teacher = Teacher::find($post->author_id);
     $category_id = CategoryPost::wherePost_id($post->id)->first()->category_id;
     $category = Category::find($category_id)->name;
     $post['category_id'] = $category_id;
     $post['category'] = $category;
     $post['author'] = $teacher->name;
     $post['fb'] = $teacher->fb;
     if (!Auth::user()) {
         $post->increment('views');
     }
     return $post;
 }
コード例 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $posts = Post::whereArchive_id($id)->paginate(Input::get('itemPerPage'));
     for ($i = 0; $i < count($posts); $i++) {
         $post = $posts[$i];
         $post = array_except($post, array("body"));
         $teacher = Teacher::find($post->author_id);
         $category_id = CategoryPost::wherePost_id($post->id)->first()->category_id;
         $category = Category::find($category_id)->name;
         $post['category'] = $category;
         $post['author'] = $teacher->name;
         $post['fb'] = $teacher->fb;
         $posts[$i] = $post;
     }
     return $posts;
 }
コード例 #3
0
 /**
  * Save List of Categories to category_post table
  * @param Post $model
  */
 private function saveCategoriesList(Post $model)
 {
     //        $model->unlinkAll('categories', true);
     $categoryPosts = $model->categoryPosts;
     foreach ($categoryPosts as $category) {
         $category->delete();
     }
     foreach ($model->categoriesList as $categoryId) {
         $categoryPost = new CategoryPost();
         $categoryPost->post_id = $model->id;
         $categoryPost->category_id = $categoryId;
         $categoryPost->save();
     }
 }
コード例 #4
0
ファイル: Category.php プロジェクト: olegigm/ghHackathon
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable(CategoryPost::tableName(), ['category_id' => 'id']);
 }
コード例 #5
0
ファイル: Post.php プロジェクト: olegigm/ghHackathon
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategoryPosts()
 {
     return $this->hasMany(CategoryPost::className(), ['post_id' => 'id']);
 }