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());
        }
  • 相关阅读:
    sphinx实时索引和高亮显示
    打开页面就进行下载的一种方法
    mysql开启慢查询日志以及查看(转载自网络)
    Best MVC Practices(最优的MVC布局)
    nginx虚拟机配置(支持php)
    一个简单大方的赞后+1,踩后-1js动画效果
    如何创建ajax对象?
    psd图片到html
    小知识
    sass入门
  • 原文地址:https://www.cnblogs.com/sgm4231/p/10186748.html
Copyright © 2011-2022 走看看