Exemplo n.º 1
0
 public function update($id, CreateArticleRequest $request)
 {
     //dd($request->input('tag_list'));
     $article = Article::find($id);
     $article->update($request->all());
     $article->tag()->sync($request->input('tag_list'));
     //return redirect('articles');
 }
 /**
  * Stores an article in the database
  * @param  CreateArticleRequest $request
  * @return view
  */
 public function store(CreateArticleRequest $request)
 {
     //Extract to function
     $tags = $request->input('tagList');
     foreach ($tags as $key => $value) {
         if (!is_numeric($value)) {
             $newTag = Tag::create(['name' => $value]);
             $tags[$key] = (string) $newTag->id;
         }
     }
     $article = \Auth::user()->articles()->create($request->all());
     $article->tags()->attach($tags);
     \Session::flash('flash_message', 'Your article has been created!');
     return redirect('articles');
 }
Exemplo n.º 3
0
 /**
  * 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');
 }
Exemplo n.º 4
0
 /**
  * Save a new article.
  *
  * @param CreateArticleRequest $request
  */
 private function createArticle(CreateArticleRequest $request)
 {
     $article = Auth::user()->articles()->create($request->all());
     //$article->uploads()->sync(Upload::put($request->file('cover')));
     $tag_list = $request->input('tag_list');
     if (!empty($tag_list)) {
         $this->syncTags($article, $request->input('tag_list'));
     }
     return $article;
 }
 public function postSearch(Article $article, CreateArticleRequest $request)
 {
     $search_text = $request->input('search_text');
     $articles = $article->postArticleSearch($search_text);
     return view('pages.searchArticle', compact('articles'));
 }
Exemplo n.º 6
0
 /**
  * Сохранение нового acticle
  * @param  Requests\CreateArticleRequest $request [description]
  * @return [type]                                 [description]
  */
 public function createArticle(Requests\CreateArticleRequest $request)
 {
     $article = Auth::user()->articles()->create($request->all());
     $this->syncTags($article, $request->input('tags_list'));
     return $article;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Article $article
  * @return Response
  */
 public function update(Article $article, CreateArticleRequest $request)
 {
     $article->update($request->all());
     $this->syncTags($article, $request->input('tag_list'));
     return redirect('articles');
 }