app/Http/Controllers/BlogController.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->validateWith([
            'blog_title' => 'required',
            'content' => 'required'
        ]);
        $img = $request->file('image');
        if($img){
        $ffname = 'feat-' . str_slug( $request->blog_title ) . '-' . str_random(8) . '.' . $img->getClientOriginalExtension();
        Image::make($img)->resize(270, 270)->save('uploads/blog/'. $ffname);
        Image::make($img)->resize(150, 150)->save('uploads/blog/thumbnails/'. $ffname);
        }
        $blog = Blog::FindOrFail($id);
        $blog->blog_title = $request->blog_title;
        $blog->slug = str_slug($request->blog_title);
        $blog->subtitle = $request->subtitle;
        if($img){
            $blog->image = $ffname;
        }
        $blog->content = $request->content;
        $blog->save();
        Session::flash('success', 'Succesfully Updated Blog');
        return redirect()->back();
    }
public function update ( Request $ request , $ id ) { $ this -> validateWith ( [ 'blog_title' => 'required' , 'content' => 'required' ] ) ; $ img = $ request -> file ( 'image' ) ; if ( $ img ) { $ ffname = 'feat-' . str_slug ( $ request -> blog_title ) . '-' . str_random ( 8 ) . '.' . $ img -> getClientOriginalExtension ( ) ; Image :: make ( $ img ) -> resize ( 270 , 270 ) -> save ( 'uploads/blog/' . $ ffname ) ; Image :: make ( $ img ) -> resize ( 150 , 150 ) -> save ( 'uploads/blog/thumbnails/' . $ ffname ) ; } $ blog = Blog :: FindOrFail ( $ id ) ; $ blog -> blog_title = $ request -> blog_title ; $ blog -> slug = str_slug ( $ request -> blog_title ) ; $ blog -> subtitle = $ request -> subtitle ; if ( $ img ) { $ blog -> image = $ ffname ; } $ blog -> content = $ request -> content ; $ blog -> save ( ) ; Session :: flash ( 'success' , 'Succesfully Updated Blog' ) ; return redirect ( ) -> back ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// 'image' => 'required',