zoukankan      html  css  js  c++  java
  • 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());
        }
  • 相关阅读:
    org-mode
    MediaWiki
    Creole
    AsciiDoc
    markdown
    图像对比度调整的simulink仿真总结
    Altera的几个常用的Synthesis attributes(转载)
    红外发送接收电路(转载)
    使用反相器的rc振荡电路
    两个小电路
  • 原文地址:https://www.cnblogs.com/sgm4231/p/10186748.html
Copyright © 2011-2022 走看看