app/Http/Controllers/PostController.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)
    {
        $post = Post::find($id);
        $post->title = $request['title'];
        $post->content = $request['content'];
        $post->category = $request['category'];
        $image = $request->file('picture');
        if ($image) {
            $image_name = $image->getClientOriginalName();
            $image->move('assets/img', $image_name);
        } else {
            $image_name = 'no_image.png';
        }
        $post->image = $image_name;
        $post->save();
        Session::flash('success', 'The post was successfully updated.');
        return redirect()->route('posts.index');
    }
public function update ( Request $ request , $ id ) { $ post = Post :: find ( $ id ) ; $ post -> title = $ request [ 'title' ] ; $ post -> content = $ request [ 'content' ] ; $ post -> category = $ request [ 'category' ] ; $ image = $ request -> file ( 'picture' ) ; if ( $ image ) { $ image_name = $ image -> getClientOriginalName ( ) ; $ image -> move ( 'assets/img' , $ image_name ) ; } else { $ image_name = 'no_image.png' ; } $ post -> image = $ image_name ; $ post -> save ( ) ; Session :: flash ( 'success' , 'The post was successfully updated.' ) ; return redirect ( ) -> route ( 'posts.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//return redirect()->route('posts.show', ['id' => $id]);