コード例 #1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $article = new Article();
     $tags = $this->tagRepository->all()->lists('name', 'id');
     $categories = $this->categoryRepository->all()->lists('name', 'id');
     $selectedTags = $article->tags()->lists('id')->toArray();
     return view('cms.articles.create', compact('tags', 'categories', 'article', 'selectedTags'));
 }
コード例 #2
0
 /**
  * Assign tags to the given article.
  *
  * @param Article $article
  * @param $tagIds
  * @return mixed
  */
 public function assignTags(Article $article, array $tagIds)
 {
     $article->tags()->sync($tagIds);
     return $article->save() ? $article : false;
 }