backend/app/Console/Commands/SitemapCreate.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $users = [];
        $pages = [];
        foreach (User::get() as $user) {
            $users[] = $this->url($user['username']);
            foreach ($user->books()->get() as $book) {
                foreach ($book->pages()->whereNotNull('parent_id')->get() as $page) {
                    $pages[] = $this->url($user['username'], $book['slug'], $page->parent_id, $page->id);
                }
            }
        }
        $sitemap = '<?xml version="1.0" encoding="UTF-8"?>
        <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
            xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
            xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
            xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">'
            . implode('', $users) .
            implode('', $pages) .
            '</urlset>';
        Storage::put('sitemap.xml', $sitemap, 'public');
        $this->info(Storage::url('public/sitemap.xml'));
    }
public function handle ( ) { $ users = [ ] ; $ pages = [ ] ; foreach ( User :: get ( ) as $ user ) { $ users [ ] = $ this -> url ( $ user [ 'username' ] ) ; foreach ( $ user -> books ( ) -> get ( ) as $ book ) { foreach ( $ book -> pages ( ) -> whereNotNull ( 'parent_id' ) -> get ( ) as $ page ) { $ pages [ ] = $ this -> url ( $ user [ 'username' ] , $ book [ 'slug' ] , $ page -> parent_id , $ page -> id ) ; } } } $ sitemap = '<?xml version="1.0" encoding="UTF-8"?>
        <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
            xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
            xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
            xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . implode ( '' , $ users ) . implode ( '' , $ pages ) . '</urlset>' ; Storage :: put ( 'sitemap.xml' , $ sitemap , 'public' ) ; $ this -> info ( Storage :: url ( 'public/sitemap.xml' ) ) ; }
Execute the console command.
Execute the console command .