2022-09-20 19:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Spatie\Sitemap\Sitemap;
|
|
|
|
use Spatie\Sitemap\Tags\Url;
|
2022-10-02 18:38:41 +00:00
|
|
|
use App\Models\Template;
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
class SitemapController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Contains route name and the associated priority
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $urls = [
|
|
|
|
['/', 1],
|
2023-12-11 13:00:42 +00:00
|
|
|
['/pricing', 0.9],
|
2022-09-20 19:59:52 +00:00
|
|
|
['/privacy-policy', 0.5],
|
|
|
|
['/terms-conditions', 0.5],
|
|
|
|
['/login', 0.4],
|
|
|
|
['/register', 0.4],
|
|
|
|
['/password/reset', 0.3],
|
2023-10-24 18:55:15 +00:00
|
|
|
['/form-templates', 0.9],
|
2022-09-20 19:59:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function getSitemap(Request $request)
|
|
|
|
{
|
|
|
|
$sitemap = Sitemap::create();
|
|
|
|
foreach ($this->urls as $url) {
|
|
|
|
$sitemap->add($this->createUrl($url[0], $url[1]));
|
|
|
|
}
|
2022-10-02 18:38:41 +00:00
|
|
|
$this->addTemplatesUrls($sitemap);
|
2023-10-24 18:55:15 +00:00
|
|
|
$this->addTemplatesTypesUrls($sitemap);
|
|
|
|
$this->addTemplatesIndustriesUrls($sitemap);
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
return $sitemap->toResponse($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createUrl($url, $priority, $frequency = 'daily')
|
|
|
|
{
|
|
|
|
return Url::create($url)->setPriority($priority)->setChangeFrequency($frequency);
|
|
|
|
}
|
2022-10-02 18:38:41 +00:00
|
|
|
|
|
|
|
private function addTemplatesUrls(Sitemap $sitemap)
|
|
|
|
{
|
2023-09-08 11:00:28 +00:00
|
|
|
Template::where('publicly_listed', true)->chunk(100, function ($templates) use ($sitemap) {
|
2022-10-02 18:38:41 +00:00
|
|
|
foreach ($templates as $template) {
|
2023-09-08 11:00:28 +00:00
|
|
|
$sitemap->add($this->createUrl('/form-templates/' . $template->slug, 0.8));
|
2022-10-02 18:38:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-10-24 18:55:15 +00:00
|
|
|
|
|
|
|
private function addTemplatesTypesUrls(Sitemap $sitemap)
|
|
|
|
{
|
|
|
|
$types = json_decode(file_get_contents(resource_path('data/forms/templates/types.json')), true);
|
|
|
|
foreach ($types as $type) {
|
|
|
|
$sitemap->add($this->createUrl('/form-templates/types/' . $type['slug'], 0.7));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addTemplatesIndustriesUrls(Sitemap $sitemap)
|
|
|
|
{
|
|
|
|
$industries = json_decode(file_get_contents(resource_path('data/forms/templates/industries.json')), true);
|
|
|
|
foreach ($industries as $industry) {
|
|
|
|
$sitemap->add($this->createUrl('/form-templates/industries/' . $industry['slug'], 0.7));
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 19:59:52 +00:00
|
|
|
}
|