Hey guys, I'm using Envoyer and I have a scheduled commands that runs daily to generate a sitemap.xml in the /public folder of my app.
The problem is the Envoyer wipes out the /public folder completely as you might know and every time I have to regenerate the sitemap.xml after every commit, which is not ideal.
@m-rk Thank you for your answer. Yes that's what I thought too, I just didn't like to have the storage prefix in the url. And yes, it seems the only way is to use symlinks.
Do you think I should create the symlink in the development environment and commit it or just create it on production?
Symlinks are not part of your code. It it something of the operating system. So you should do it on your production server.
An alternative solution that I use at this moment because I run multiple sites on the same application is to create a route called sitemap.xml that resolves to SitemapController.php and inside that controller I search for the sitemap in my storage directory and return the file if it exists. This is slower than a symlink but this works good for me.
class SitemapController extends Controller
{
public function index()
{
$path = site()->key . '/sitemap.xml';
if (!Storage::disk('local')->exists($path)) {
return response()->redirectTo('/');
}
// get the sitemap and check if it has content
$xml = Storage::disk('local')->get($path);
if (!$xml) {
return response()->redirectTo('/');
}
// get the xml from the storage and present it
return response($xml, 200, ['Content-Type' => 'text/xml']);
}
}