app/Http/Controllers/Admin/PostController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Post  $post
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Post $post)
    {
        $request->validate($this->validations);
        $data = $request->all();
        if ($post->title == $data['title']) {
            $tempSlug = $post->slug;
        } else {
            $tempSlug = Str::of($data['title'])->slug("-");
            $count = 1;
            while (Post::where('slug', $tempSlug)->where('id', '!=', $post->id)->first()) {
                $tempSlug = Str::of($data['title'])->slug("-") . '-' . $count;
                $count ++;
            }
        }
        $data['slug'] = $tempSlug;
        if(isset($data['image'])){
            $imgPath = Storage::put('uploads', $data['image']);
            $data['image'] = $imgPath;
        }
        $post->update($data);
        $post->tags()->sync(isset($data['tags']) ? $data['tags'] : []);
        return redirect()->route('admin.posts.show', $post->id);
    }
public function update ( Request $ request , Post $ post ) { $ request -> validate ( $ this -> validations ) ; $ data = $ request -> all ( ) ; if ( $ post -> title == $ data [ 'title' ] ) { $ tempSlug = $ post -> slug ; } else { $ tempSlug = Str :: of ( $ data [ 'title' ] ) -> slug ( " - " ) ; $ count = 1 ; while ( Post :: where ( 'slug' , $ tempSlug ) -> where ( 'id' , '!=' , $ post -> id ) -> first ( ) ) { $ tempSlug = Str :: of ( $ data [ 'title' ] ) -> slug ( " - " ) . '-' . $ count ; $ count ++ ; } } $ data [ 'slug' ] = $ tempSlug ; if ( isset ( $ data [ 'image' ] ) ) { $ imgPath = Storage :: put ( 'uploads' , $ data [ 'image' ] ) ; $ data [ 'image' ] = $ imgPath ; } $ post -> update ( $ data ) ; $ post -> tags ( ) -> sync ( isset ( $ data [ 'tags' ] ) ? $ data [ 'tags' ] : [ ] ) ; return redirect ( ) -> route ( 'admin.posts.show' , $ post -> id ) ; }
Update the specified resource in storage.
Update the specified resource in storage .