0

I'm writing a laravel package which contains spatie/laravel-sitemap.

I already included several external packages and I didn't encountered any issues, but for some reason I'm not able to integrate this one.

What I did is the usual:

composer require spatie/laravel-sitemap

Then I have created a Console command that have as handle method the following content:

public function handle()
{
    SitemapGenerator::create(config('app.url'))
        ->configureCrawler(function (Crawler $crawler) {
            $crawler->ignoreRobots();
        })
        ->writeToFile(public_path('sitemap.xml'));

    $this->line('<info>Sitemap generated');
}

when I execute the command registered as:

php artisan myapp:sitemap

I get:

 Class "Spatie\Sitemap\SitemapGenerator" not found

The reference imported are:

use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;

I also tried composer update and composer dump-autoload, same problem.

Any help?

sfarzoso
  • 1,356
  • 2
  • 24
  • 65

2 Answers2

1

register package class in providers array in config/app.php

Spatie\Sitemap\SitemapServiceProvider;

in the bottom of app.php file

i hope it was useful.

Joukhar
  • 724
  • 1
  • 3
  • 18
  • I've added this line but same issue – sfarzoso Jul 28 '22 at 15:51
  • i will try the package and i will update the answer if there any solution – Joukhar Jul 28 '22 at 15:53
  • Yes, but you should test the package creating a laravel package, not installing it directly on the project. Because I tried to install the package directly on the probject and it works, the issue is raised when is installed on another package – sfarzoso Jul 28 '22 at 15:55
  • i have no knowledge about creating laravel packages so i'm sorry. – Joukhar Jul 28 '22 at 15:58
0

you can publish package using this.

php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=sitemap-config

then

composer dump-autoload

for more details please check the document https://github.com/spatie/laravel-sitemap under Configuration

Manish J
  • 686
  • 1
  • 8
  • 24