/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Requests\CreateArticleRequest $request * @return \Illuminate\Http\Response */ public function store(CreateArticleRequest $request) { $tags = $request->input('tags'); $currentTags = array_filter($tags, 'is_numeric'); $newTags = array_diff($tags, $currentTags); foreach ($newTags as $newTag) { if ($tag = Tag::create(['name' => $newTag])) { $currentTags[] = $tag->id; } } // $article = Auth::user()->articles()->create($request->all()); $article = Article::create($request->all()); $article->tags()->attach($currentTags); // $article->tags()->sync($currentTags); if ($request->hasFile('cover')) { $this->uploadFile($request->file('cover')); } return redirect('admin/content'); }