app/Http/Controllers/ArticlesController.php
/*
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(ArticleRequest $request, $id)
    {
       $article =Article::find($id);
        $article->title =$request->title;
        $article->preview = $request->preview;
        $article->category_id = $request->category_id;
        $article->content = $request->content;
        $article->statu_id = $request->statu_id;
        $article->slug = Str::slug($request->title);
        $article->user_id = \Auth::user()->id;
        $article->save();
        $article->setTags($request->tags);
        if($request->file("image")){
            $file = $request->file("image");
            $name = 'blog_'.time().'.'.$file->getClientOriginalExtension();
            $path = $request->file('image')->storeAs('images',$name);
            $image= new Image();
            $image->name = $name ;
            $image->article()->associate($article);
            $image->save();
        }
        Flash::success("Se ha actualizado el articulo <b>$article->title</b>");
        return redirect()->route('articles.index');
    }
public function update ( ArticleRequest $ request , $ id ) { $ article = Article :: find ( $ id ) ; $ article -> title = $ request -> title ; $ article -> preview = $ request -> preview ; $ article -> category_id = $ request -> category_id ; $ article -> content = $ request -> content ; $ article -> statu_id = $ request -> statu_id ; $ article -> slug = Str :: slug ( $ request -> title ) ; $ article -> user_id = \ Auth :: user ( ) -> id ; $ article -> save ( ) ; $ article -> setTags ( $ request -> tags ) ; if ( $ request -> file ( " image " ) ) { $ file = $ request -> file ( " image " ) ; $ name = 'blog_' . time ( ) . '.' . $ file -> getClientOriginalExtension ( ) ; $ path = $ request -> file ( 'image' ) -> storeAs ( 'images' , $ name ) ; $ image = new Image ( ) ; $ image -> name = $ name ; $ image -> article ( ) -> associate ( $ article ) ; $ image -> save ( ) ; } Flash :: success ( " Se ha actualizado el articulo <b> $ article -> title </b> " ) ; return redirect ( ) -> route ( 'articles.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .