|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Post; |
|
6
|
|
|
use App\Services\PostService; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Spatie\Sitemap\Sitemap; |
|
9
|
|
|
use Spatie\Sitemap\Tags\Url; |
|
10
|
|
|
|
|
11
|
|
|
class GenerateSitemap extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'sitemap:generate'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Generate the sitemap'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Create a new command instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
private PostService $postService; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct( |
|
35
|
|
|
PostService $postService |
|
36
|
|
|
) { |
|
37
|
|
|
parent::__construct(); |
|
38
|
|
|
$this->postService = $postService; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Execute the console command. |
|
43
|
|
|
* |
|
44
|
|
|
* @return int |
|
45
|
|
|
*/ |
|
46
|
|
|
public function handle() |
|
47
|
|
|
{ |
|
48
|
|
|
$sitemap = Sitemap::create() |
|
49
|
|
|
->add(Url::create('/blog')) |
|
50
|
|
|
->add(Url::create('/next_events')) |
|
51
|
|
|
->add(Url::create('/treatments-ilan-lev-method')) |
|
52
|
|
|
->add(Url::create('/contact-improvisation')) |
|
53
|
|
|
->add(Url::create('/getATreatment')) |
|
54
|
|
|
->add(Url::create('/aboutMe')) |
|
55
|
|
|
->add(Url::create('/contact')); |
|
56
|
|
|
|
|
57
|
|
|
/*$posts = $this->postService->getPosts(null, ['status' => 'published']); |
|
58
|
|
|
foreach ($posts as $post) { |
|
59
|
|
|
$sitemap->add(Url::create("/posts/{$post->slug}")); |
|
60
|
|
|
}*/ |
|
61
|
|
|
$sitemap->writeToFile(public_path('sitemap.xml')); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|