• laravel 网站地图轮子


    https://github.com/Laravelium/laravel-sitemap

    add the following to your composer.json file :

    For Laravel 5.7

    "laravelium/sitemap": "3.0.*"

    For Laravel 5.6

    "laravelium/sitemap": "2.8.*"

    For Laravel 5.5

    "laravelium/sitemap": "2.7.*"

    Publish needed assets (styles, views, config files) :

    php artisan vendor:publish --provider="LaraveliumSitemapSitemapServiceProvider"

    Note: Composer won't update them after composer update, you'll need to do it manually!

    public function sitemap(Request $request) {
            // create new sitemap object
            $sitemap = App::make("sitemap");
            $sitemap->setCache('laravel.sitemap', 60);
            // get all posts from db
            $posts = News::where('audit_status', 0)
                ->orderBy('id', 'desc')
                ->get();
            // add every post to the sitemap
            foreach ($posts as $post) {
    
                $sitemap->add(getenv('APP_URL')."/news/".$post->id.'.html', $post->created_at, 0.9, 'monthly');
            }
    
            $sitemap->add(getenv('APP_URL')."/news.html", $post->created_at, 1, 'monthly');
    
            $xml=$sitemap->render('xml');
    
    //        header('Content-Type: application/xml');
    //        header('Content-Disposition: attachment;filename="sitemap.xml"');
            $path=public_path()."sitemap.xml";
            $path=str_replace('\','/',$path);
    
            return file_put_contents($path,$xml->getContent());
        }
  • 相关阅读:
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    非数值数据的编码方式
    定点数
    C语言||作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
  • 原文地址:https://www.cnblogs.com/sgm4231/p/10186748.html
Copyright © 2020-2023  润新知