app/Http/Controllers/PostsController.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(Request $request, $id)
    {
        $this->validate($request, [
            'title' => 'required',
            'content' => 'required',
            'category_id' => 'required'
        ]);
        $post = Post::find($id);
        if($request->hasFile('featured'))
        {
            $featured = $request->featured;
            $featured_new_name = time().$featured->getClientOriginalName();
            $featured->move('uploads/posts', $featured_new_name);
            $post->featured = 'uploads/posts/'.$featured_new_name;
        }
        $post->title = $request->title;
        $post->content = $request->content;
        $post->category_id = $request->category_id;
        $post->save();
        $post->tags()->sync($request->tags);
        Session::flash('success', 'Post updated succesfully');
        return redirect()->route('posts');
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'title' => 'required' , 'content' => 'required' , 'category_id' => 'required' ] ) ; $ post = Post :: find ( $ id ) ; if ( $ request -> hasFile ( 'featured' ) ) { $ featured = $ request -> featured ; $ featured_new_name = time ( ) . $ featured -> getClientOriginalName ( ) ; $ featured -> move ( 'uploads/posts' , $ featured_new_name ) ; $ post -> featured = 'uploads/posts/' . $ featured_new_name ; } $ post -> title = $ request -> title ; $ post -> content = $ request -> content ; $ post -> category_id = $ request -> category_id ; $ post -> save ( ) ; $ post -> tags ( ) -> sync ( $ request -> tags ) ; Session :: flash ( 'success' , 'Post updated succesfully' ) ; return redirect ( ) -> route ( 'posts' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .