public function update($blog, $payload)
    {
        $payload = $this->parseBlocks($payload, 'blog');

        $payload['title'] = htmlentities($payload['title']);

        if (isset($payload['hero_image'])) {
            app(FileService::class)->delete($blog->hero_image);
            $file = request()->file('hero_image');
            $path = app(FileService::class)->saveFile($file, 'public/images', [], true);
            $payload['hero_image'] = $path['name'];
        }

        if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) {
            return $this->translationRepo->createOrUpdate($blog->id, 'Grafite\Cms\Models\Blog', $payload['lang'], $payload);
        } else {
            $payload['url'] = Cms::convertToURL($payload['url']);
            $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
            $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');

            unset($payload['lang']);

            return $blog->update($payload);
        }
    }
public function update($blog, $payload)
    {
        $payload = $this->parseBlocks($payload, 'blog');

        $payload['title'] = htmlentities($payload['title']);

        if (isset($payload['hero_image'])) {
            app(FileService::class)->delete($blog->hero_image);
            $file = request()->file('hero_image');
            $path = app(FileService::class)->saveFile($file, 'public/images', [], true);
            $payload['hero_image'] = $path['name'];
        }

        if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) {
            return $this->translationRepo->createOrUpdate($blog->id, 'Grafite\Cms\Models\Blog', $payload['lang'], $payload);
        } else {
            $payload['url'] = Cms::convertToURL($payload['url']);
            $payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
            $payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');

            unset($payload['lang']);

            return $blog->update($payload);
        }
    }
public function update ( $ blog , $ payload ) { $ payload = $ this -> parseBlocks ( $ payload , 'blog' ) ; $ payload [ 'title' ] = htmlentities ( $ payload [ 'title' ] ) ; if ( isset ( $ payload [ 'hero_image' ] ) ) { app ( FileService :: class ) -> delete ( $ blog -> hero_image ) ; $ file = request ( ) -> file ( 'hero_image' ) ; $ path = app ( FileService :: class ) -> saveFile ( $ file , 'public/images' , [ ] , true ) ; $ payload [ 'hero_image' ] = $ path [ 'name' ] ; } if ( ! empty ( $ payload [ 'lang' ] ) && $ payload [ 'lang' ] !== config ( 'cms.default-language' , 'en' ) ) { return $ this -> translationRepo -> createOrUpdate ( $ blog -> id , 'Grafite\Cms\Models\Blog' , $ payload [ 'lang' ] , $ payload ) ; } else { $ payload [ 'url' ] = Cms :: convertToURL ( $ payload [ 'url' ] ) ; $ payload [ 'is_published' ] = ( isset ( $ payload [ 'is_published' ] ) ) ? ( bool ) $ payload [ 'is_published' ] : 0 ; $ payload [ 'published_at' ] = ( isset ( $ payload [ 'published_at' ] ) && ! empty ( $ payload [ 'published_at' ] ) ) ? Carbon :: parse ( $ payload [ 'published_at' ] ) -> format ( 'Y-m-d H:i:s' ) : Carbon :: now ( config ( 'app.timezone' ) ) -> format ( 'Y-m-d H:i:s' ) ; unset ( $ payload [ 'lang' ] ) ; return $ blog -> update ( $ payload ) ; } }
Updates Blog into database.

@param Blog  $blog
@param array $input

@return Blog
Updates Blog into database .