sebacarrasco93/laravel-simple-sitemap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sebacarrasco93/laravel-simple-sitemap

最新稳定版本:1.0.2

Composer 安装命令:

composer require sebacarrasco93/laravel-simple-sitemap

包简介

Laravel Simple Sitemap

README 文档

README

A very simple package: Create sitemaps "on the fly"

Installation

You can install the package via composer:

composer require sebacarrasco93/laravel-simple-sitemap

You can publish the config file with:

php artisan vendor:publish --tag="simple-sitemap-config"

This is the contents of the published config file:

return [    

    'default_frequency' => 'monthly',
    
    'default_priority' => '0.50',
];

Usage

Create a sitemap for Eloquent Collections

Let's assume that you want to make a sitemap of all the categories, you can do that in only 3 steps!

// app/Models/Category

use SebaCarrasco93\SimpleSitemap\Traits\SimpleSitemapCollection; // 👈 1: Import Trait

class Category extends Model
{
    use HasFactory;
    // ...
    use SimpleSitemapCollection; // 👈 2: Use the trait

    // ...

    // 👇 Step 3: Create getSitemapUrlAttribute() method and specify the full url
    public function getSitemapUrlAttribute(): string 
    {
        return route('category.show', $this);
    }
}

Now, you can use it

// web.php, controller or equivalent

$categories = Category::get();

return SimpleSitemap::fromEloquentCollection($categories);

Can I short the syntax? Of course!

return Category::sitemap(); // Equivalent to SimpleSitemap::fromEloquentCollection(Category::get());

Advanced usage

A sitemap for only active categories? Sure!

return Category::where('active', true)
    ->sitemap();

A sitemap for active, and only 10 last categories? It's Eloquent and Laravel!

$active_categories = Category::where('active', true)
    ->orderBy('desc', 'id')->take(10)->get();

return SimpleSitemap::fromCollection($active_categories);

Easy Peasy!

Optionally, you can create a index sitemap with your sitemap collections

$routes = [
    route('sitemaps/index-1'), // You can pass it as a route
    'https://yourdomain.com/sitemaps/index-2', // or, as full path
    '/sitemaps/index-3', // as a relative path, too
];

return SimpleSitemap::index($routes);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-07