some progress
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\CheckDomainExpiry;
|
||||
use App\Models\Domain;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DomainController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$domains = Domain::with('site')
|
||||
->where('is_active', true)
|
||||
->orderBy('expires_at', 'asc')
|
||||
->paginate(15);
|
||||
|
||||
return view('domains.index', compact('domains'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$sites = Site::where('user_id', auth()->id())
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('domains.create', compact('sites'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'site_id' => 'required|exists:sites,id',
|
||||
'domain' => 'required|string|max:255',
|
||||
'is_active' => 'sometimes|nullable|in:on,off',
|
||||
]);
|
||||
|
||||
$validated['is_active'] = $request->has('is_active');
|
||||
|
||||
$domain = Domain::create($validated);
|
||||
|
||||
// Dispatch job to check domain immediately
|
||||
CheckDomainExpiry::dispatch($domain);
|
||||
|
||||
return redirect()
|
||||
->route('domains.index')
|
||||
->with('success', 'Domain added successfully. Checking expiry date...');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Domain $domain)
|
||||
{
|
||||
$domain->load('site');
|
||||
|
||||
return view('domains.show', compact('domain'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Domain $domain)
|
||||
{
|
||||
$sites = Site::where('user_id', auth()->id())
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return view('domains.edit', compact('domain', 'sites'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Domain $domain)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'site_id' => 'required|exists:sites,id',
|
||||
'domain' => 'required|string|max:255',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$validated['is_active'] = $request->has('is_active');
|
||||
|
||||
$domain->update($validated);
|
||||
|
||||
return redirect()
|
||||
->route('domains.index')
|
||||
->with('success', 'Domain updated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Domain $domain)
|
||||
{
|
||||
$domain->delete();
|
||||
|
||||
return redirect()
|
||||
->route('domains.index')
|
||||
->with('success', 'Domain deleted successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually trigger domain expiry check
|
||||
*/
|
||||
public function check(Domain $domain)
|
||||
{
|
||||
CheckDomainExpiry::dispatch($domain);
|
||||
|
||||
return back()
|
||||
->with('success', 'Domain expiry check has been queued.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user