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);
        $this->validate($request,[
            'title' => 'required|max:255',
            'content' => 'required',
            'user_id' => 'required',
            'category_id' => 'required',
            'keyword' => 'max:255',
            'short_desc' => 'max:500',
            'price' => 'integer'
        ]);
        if($request->hasFile('featured'))
        {
            $featured = $request ->featured;
            $image_new_name = time().$featured->getClientOriginalName();
            $featured->move('admin/uploads/images/',$image_new_name);
            $post->featured = 'admin/uploads/images/'.$image_new_name;
        }
        $post->title = $request->title;
        $post->keyword = $request->keyword;
        $post->short_desc = $request->short_desc;
        $post->content = $request->content;
        $post->category_id = $request->category_id;
        $post->slug = str_slug($request->title);
        $post->tags()->attach($request->tags);
        $post->save();
        Session::flask('success','Post updated succesfully.');
        return redirect()->route('post.index');
    }
public function update ( Request $ request , $ id ) { $ post = Post :: find ( $ id ) ; $ this -> validate ( $ request , [ 'title' => 'required|max:255' , 'content' => 'required' , 'user_id' => 'required' , 'category_id' => 'required' , 'keyword' => 'max:255' , 'short_desc' => 'max:500' , 'price' => 'integer' ] ) ; if ( $ request -> hasFile ( 'featured' ) ) { $ featured = $ request -> featured ; $ image_new_name = time ( ) . $ featured -> getClientOriginalName ( ) ; $ featured -> move ( 'admin/uploads/images/' , $ image_new_name ) ; $ post -> featured = 'admin/uploads/images/' . $ image_new_name ; } $ post -> title = $ request -> title ; $ post -> keyword = $ request -> keyword ; $ post -> short_desc = $ request -> short_desc ; $ post -> content = $ request -> content ; $ post -> category_id = $ request -> category_id ; $ post -> slug = str_slug ( $ request -> title ) ; $ post -> tags ( ) -> attach ( $ request -> tags ) ; $ post -> save ( ) ; Session :: flask ( 'success' , 'Post updated succesfully.' ) ; return redirect ( ) -> route ( 'post.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .