app/Console/Commands/CreateSitemapVatgia.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $time_now = time();
        $page = 1;
        $this->info("Inserting classified data....");
        $max_row = 1000;
        $storage_path = storage_path();
        $sitemap_path = $storage_path . "/sitemap/";
        $google_key_path = $storage_path . "/google/sosanhnha-cc58dade1d96.json";
        if(!file_exists(dirname($sitemap_path))) mkdir(dirname($sitemap_path), 0777, true);
        $domainSitemap = "https:vatgia.com/batdongsan/";
        $sitemap = new Sitemap($sitemap_path . '/realestate.xml');
        $sitemap->setMaxUrls(20000);
        for (; ;) {
            $offset = $page * $max_row - $max_row;
            $myModel = new RewriteNoaccent();
            $myModel = $myModel->where('rew_table','=','category_address')->offset($offset)->limit($max_row)->get();
            if ($myModel->count() == 0) break;
            $data = [];
            foreach ($myModel as $row) {
                $row = $row->toArray();
                $sitemap->addItem($domainSitemap . $row["rew_rewrite"], time(), Sitemap::DAILY, 0.3);
            }
            $this->info($offset);
            $page++;
        }
        $sitemap->write();
        $files = scandir ($sitemap_path);
        $index = new Index($sitemap_path . 'sitemap.xml');
        foreach($files as $file){
            if(strpos($file,".xml") !== false && $file != "sitemap.xml" && $file != "sitemap-new.xml") $index->addSitemap($domainSitemap . $file);
        }
        $index->write();
    }
public function handle ( ) { $ time_now = time ( ) ; $ page = 1 ; $ this -> info ( " Inserting classified data.... " ) ; $ max_row = 1000 ; $ storage_path = storage_path ( ) ; $ sitemap_path = $ storage_path . " /sitemap/ " ; $ google_key_path = $ storage_path . " /google/sosanhnha-cc58dade1d96.json " ; if ( ! file_exists ( dirname ( $ sitemap_path ) ) ) mkdir ( dirname ( $ sitemap_path ) , 0777 , true ) ; $ domainSitemap = " https://vatgia.com/batdongsan/ " ; $ sitemap = new Sitemap ( $ sitemap_path . '/realestate.xml' ) ; $ sitemap -> setMaxUrls ( 20000 ) ; for ( ; ; ) { $ offset = $ page * $ max_row - $ max_row ; $ myModel = new RewriteNoaccent ( ) ; $ myModel = $ myModel -> where ( 'rew_table' , '=' , 'category_address' ) -> offset ( $ offset ) -> limit ( $ max_row ) -> get ( ) ; if ( $ myModel -> count ( ) == 0 ) break ; $ data = [ ] ; foreach ( $ myModel as $ row ) { $ row = $ row -> toArray ( ) ; $ sitemap -> addItem ( $ domainSitemap . $ row [ " rew_rewrite " ] , time ( ) , Sitemap :: DAILY , 0.3 ) ; } $ this -> info ( $ offset ) ; $ page ++ ; } $ sitemap -> write ( ) ; $ files = scandir ( $ sitemap_path ) ; $ index = new Index ( $ sitemap_path . 'sitemap.xml' ) ; foreach ( $ files as $ file ) { if ( strpos ( $ file , " .xml " ) !== false && $ file != " sitemap.xml " && $ file != " sitemap-new.xml " ) $ index -> addSitemap ( $ domainSitemap . $ file ) ; } $ index -> write ( ) ; }
Execute the console command.
Execute the console command .
//$sitemap->setUseGzip(true); //$sitemap->setBufferSize(20); //$sitemap->setMaxBytes(20485760); // add some URLs //