2

I'm using laravel-sitemap in order to create sitemap.xml file for laravel website. Here are route and controller.

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url;
use App\Models\Post;


class SiteMapController extends Controller
{
    /**
     * generates the sitemap xml file
     */
    public function generate()
    {
        $sitemap = Sitemap::create();
       
        $post = Post::all();
        foreach ($post as $post) {
            $sitemap->add(Url::create("/post/{$post->slug}"));
        }
        $sitemap->writeToFile(public_path('sitemap.xml'));

        return redirect()->route('admin.dashboard')->withSuccess(__('sitemap.updated'));

    }
}
Route::get('generate-sitemap', 'SiteMapController@generate');

Everything works correctly in localhost but in remote shared host it returns the following error:

No hint path defined for [sitemap].
Mahdi
  • 664
  • 3
  • 15
  • 35

2 Answers2

2

I had the same issue I ran:

php artisan optimize:clear
php artisan cache:clear
php artisan view:clear

Then it worked.

0

Answer of @Mark Tierney is working for me. Those who're using cPanel and don't have terminal access, they can make a route and execute the operations.

use Illuminate\Support\Facades\Artisan;
Route::get('/optimize-clear', function(){
    Artisan::call('optimize:clear');
    Artisan::call('cache:clear');
    Artisan::call('view:clear');
    echo 'Cache cleared successfully!';
});
Shahriar Rahat
  • 261
  • 3
  • 6