126 lines
3.0 KiB
PHP
126 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Jobs\CheckSitemap;
|
|
use App\Models\Sitemap;
|
|
use App\Models\Site;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SitemapController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$sitemaps = Sitemap::with('site')
|
|
->where('is_active', true)
|
|
->orderBy('is_valid', 'asc')
|
|
->orderBy('last_checked_at', 'desc')
|
|
->paginate(15);
|
|
|
|
return view('sitemaps.index', compact('sitemaps'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
$sites = Site::where('user_id', auth()->id())
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return view('sitemaps.create', compact('sites'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'site_id' => 'required|exists:sites,id',
|
|
'url' => 'required|url|max:500',
|
|
'is_active' => 'sometimes|nullable|in:on,off',
|
|
]);
|
|
|
|
$validated['is_active'] = $request->has('is_active');
|
|
|
|
$sitemap = Sitemap::create($validated);
|
|
|
|
// Dispatch job to check sitemap immediately
|
|
CheckSitemap::dispatch($sitemap);
|
|
|
|
return redirect()
|
|
->route('sitemaps.index')
|
|
->with('success', 'Sitemap added successfully. Validating now...');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Sitemap $sitemap)
|
|
{
|
|
$sitemap->load('site');
|
|
|
|
return view('sitemaps.show', compact('sitemap'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Sitemap $sitemap)
|
|
{
|
|
$sites = Site::where('user_id', auth()->id())
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return view('sitemaps.edit', compact('sitemap', 'sites'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Sitemap $sitemap)
|
|
{
|
|
$validated = $request->validate([
|
|
'site_id' => 'required|exists:sites,id',
|
|
'url' => 'required|url|max:500',
|
|
'is_active' => 'boolean',
|
|
]);
|
|
|
|
$validated['is_active'] = $request->has('is_active');
|
|
|
|
$sitemap->update($validated);
|
|
|
|
return redirect()
|
|
->route('sitemaps.index')
|
|
->with('success', 'Sitemap updated successfully.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Sitemap $sitemap)
|
|
{
|
|
$sitemap->delete();
|
|
|
|
return redirect()
|
|
->route('sitemaps.index')
|
|
->with('success', 'Sitemap deleted successfully.');
|
|
}
|
|
|
|
/**
|
|
* Manually trigger sitemap validation
|
|
*/
|
|
public function check(Sitemap $sitemap)
|
|
{
|
|
CheckSitemap::dispatch($sitemap);
|
|
|
|
return back()
|
|
->with('success', 'Sitemap validation has been queued.');
|
|
}
|
|
}
|