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)
    {
         $this->validate($request,[
            'title'=>'required',
            'description'=>'required',
            'body'=>'required',
            'image'=>'image|mimes:png,jpg,jpeg,max:10000',
            ]);
        if($request->hasFile('image')){
            $imageName = $request->image->getClientOriginalName();
            $request ->image->move('images',$imageName);
            $formInput =  Post::find($id);
            $formInput->title = $request->title;
            $formInput->description = $request->description;
            $formInput->body = $request->body;
            $formInput->image = $imageName;
            $formInput->active = $request->active;
            $formInput->update();
            session()->flash('notify', 'Post Successfully Updated');
            return redirect()->route('post.index');
        }
    }
public function update ( Request $ request , $ id ) { $ this -> validate ( $ request , [ 'title' => 'required' , 'description' => 'required' , 'body' => 'required' , 'image' => 'image|mimes:png,jpg,jpeg,max:10000' , ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ imageName = $ request -> image -> getClientOriginalName ( ) ; $ request -> image -> move ( 'images' , $ imageName ) ; $ formInput = Post :: find ( $ id ) ; $ formInput -> title = $ request -> title ; $ formInput -> description = $ request -> description ; $ formInput -> body = $ request -> body ; $ formInput -> image = $ imageName ; $ formInput -> active = $ request -> active ; $ formInput -> update ( ) ; session ( ) -> flash ( 'notify' , 'Post Successfully Updated' ) ; return redirect ( ) -> route ( 'post.index' ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .