2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Domains;
|
2022-05-16 06:43:33 +02:00
|
|
|
use App\Models\Home;
|
2022-03-05 16:02:12 +01:00
|
|
|
use App\Models\Labels;
|
|
|
|
use App\Models\Pricing;
|
|
|
|
use App\Models\Providers;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class DomainsController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2022-07-19 16:19:05 +02:00
|
|
|
$domains = Domains::allDomains();
|
2022-03-05 16:02:12 +01:00
|
|
|
return view('domains.index', compact(['domains']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Domains $domain)
|
2022-07-19 16:19:05 +02:00
|
|
|
{//Need to modern
|
2022-09-22 05:20:23 +02:00
|
|
|
$domain_info = Domains::domain($domain->id);
|
2022-07-19 16:19:05 +02:00
|
|
|
return view('domains.show', compact(['domain_info']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
2022-05-15 08:22:47 +02:00
|
|
|
return view('domains.create');
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'domain' => 'required|string|min:2',
|
|
|
|
'extension' => 'required|string|min:2',
|
|
|
|
'ns1' => 'sometimes|nullable|min:2',
|
|
|
|
'ns2' => 'sometimes|nullable|min:2',
|
|
|
|
'ns3' => 'sometimes|nullable|min:2',
|
|
|
|
'provider_id' => 'integer',
|
|
|
|
'payment_term' => 'integer',
|
2022-03-05 16:02:12 +01:00
|
|
|
'price' => 'numeric',
|
2022-10-20 02:06:44 +02:00
|
|
|
'next_due_date' => 'required|date',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
|
|
|
'label1' => 'sometimes|nullable|string',
|
|
|
|
'label2' => 'sometimes|nullable|string',
|
|
|
|
'label3' => 'sometimes|nullable|string',
|
|
|
|
'label4' => 'sometimes|nullable|string',
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$domain_id = Str::random(8);
|
|
|
|
$pricing = new Pricing();
|
2022-08-30 15:37:05 +02:00
|
|
|
$pricing->insertPricing(4, $domain_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Domains::create([
|
|
|
|
'id' => $domain_id,
|
|
|
|
'domain' => $request->domain,
|
|
|
|
'extension' => $request->extension,
|
|
|
|
'ns1' => $request->ns1,
|
|
|
|
'ns2' => $request->ns2,
|
|
|
|
'ns3' => $request->ns3,
|
|
|
|
'provider_id' => $request->provider_id,
|
|
|
|
'owned_since' => $request->owned_since
|
|
|
|
]);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain_id);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
Cache::forget("all_domains");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('domains.index')
|
|
|
|
->with('success', 'Domain Created Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Domains $domain)
|
|
|
|
{
|
2022-09-22 05:20:23 +02:00
|
|
|
$domain_info = Domains::domain($domain->id);
|
2022-07-19 16:19:05 +02:00
|
|
|
return view('domains.edit', compact(['domain_info']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, Domains $domain)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'domain' => 'required|string|min:2',
|
|
|
|
'extension' => 'required|string|min:2',
|
|
|
|
'ns1' => 'sometimes|nullable|min:2',
|
|
|
|
'ns2' => 'sometimes|nullable|min:2',
|
|
|
|
'ns3' => 'sometimes|nullable|min:2',
|
|
|
|
'provider_id' => 'integer',
|
|
|
|
'payment_term' => 'integer',
|
|
|
|
'price' => 'numeric',
|
|
|
|
'next_due_date' => 'required|date',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
|
|
|
'label1' => 'sometimes|nullable|string',
|
|
|
|
'label2' => 'sometimes|nullable|string',
|
|
|
|
'label3' => 'sometimes|nullable|string',
|
|
|
|
'label4' => 'sometimes|nullable|string',
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$pricing = new Pricing();
|
|
|
|
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
2022-05-14 16:43:36 +02:00
|
|
|
$pricing->updatePricing($domain->id, $request->currency, $request->price, $request->payment_term, $as_usd, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
$domain->update([
|
|
|
|
'domain' => $request->domain,
|
|
|
|
'extension' => $request->extension,
|
|
|
|
'ns1' => $request->ns1,
|
|
|
|
'ns2' => $request->ns2,
|
|
|
|
'ns3' => $request->ns3,
|
|
|
|
'provider_id' => $request->provider_id,
|
|
|
|
'owned_since' => $request->owned_since,
|
|
|
|
'active' => (isset($request->is_active)) ? 1 : 0
|
|
|
|
]);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Labels::deleteLabelsAssignedTo($domain->id);
|
|
|
|
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain->id);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
Cache::forget("all_domains");
|
|
|
|
Cache::forget("domain.{$domain->id}");
|
2022-05-15 08:22:47 +02:00
|
|
|
Cache::forget("labels_for_service.{$domain->id}");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('domains.index')
|
|
|
|
->with('success', 'Domain Updated Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Domains $domain)
|
|
|
|
{
|
|
|
|
$items = Domains::find($domain->id);
|
|
|
|
$items->delete();
|
|
|
|
|
|
|
|
$p = new Pricing();
|
|
|
|
$p->deletePricing($domain->id);
|
|
|
|
|
|
|
|
Labels::deleteLabelsAssignedTo($domain->id);
|
|
|
|
|
2022-07-19 16:19:05 +02:00
|
|
|
Cache::forget("all_domains");
|
|
|
|
Cache::forget("domain.{$domain->id}");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('domains.index')
|
|
|
|
->with('success', 'Domain was deleted Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|