2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Domains;
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
$domains = DB::table('domains as d')
|
|
|
|
->join('providers as p', 'd.provider_id', '=', 'p.id')
|
|
|
|
->join('pricings as pr', 'd.id', '=', 'pr.service_id')
|
|
|
|
->get(['d.*', 'p.name as provider_name', 'pr.*']);
|
|
|
|
|
|
|
|
return view('domains.index', compact(['domains']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Domains $domain)
|
|
|
|
{
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
$service_extras = DB::table('domains as d')
|
|
|
|
->join('providers as p', 'd.provider_id', '=', 'p.id')
|
|
|
|
->join('pricings as pr', 'd.id', '=', 'pr.service_id')
|
|
|
|
->where('d.id', '=', $domain->id)
|
|
|
|
->get(['d.*', 'p.name as provider_name', 'pr.*']);
|
|
|
|
|
2022-03-05 16:58:25 +01:00
|
|
|
$labels = DB::table('labels_assigned as l')
|
|
|
|
->join('labels', 'l.label_id', '=', 'labels.id')
|
|
|
|
->where('l.service_id', '=', $domain->id)
|
|
|
|
->get(['labels.label']);
|
|
|
|
|
|
|
|
return view('domains.show', compact(['domain', 'service_extras', 'labels']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
2022-05-09 07:39:03 +02:00
|
|
|
$Providers = Providers::allProviders();
|
2022-03-05 16:02:12 +01:00
|
|
|
return view('domains.create', compact('Providers'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'domain' => 'required|min:2',
|
|
|
|
'extension' => 'required|min:2',
|
|
|
|
'provider_id' => 'numeric',
|
|
|
|
'price' => 'numeric',
|
|
|
|
'next_due_date' => 'required|date'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$domain_id = Str::random(8);
|
|
|
|
|
|
|
|
$pricing = new Pricing();
|
|
|
|
|
|
|
|
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
|
|
|
|
2022-05-14 16:24:05 +02:00
|
|
|
$pricing->insertPricing(4, $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
|
|
|
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-03-05 16:58:25 +01:00
|
|
|
Cache::forget('services_count');//Main page services_count cache
|
|
|
|
Cache::forget('due_soon');//Main page due_soon cache
|
|
|
|
Cache::forget('recently_added');//Main page recently_added cache
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('domains.index')
|
|
|
|
->with('success', 'Domain Created Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Domains $domain)
|
|
|
|
{
|
|
|
|
$domain_info = DB::table('domains as d')
|
|
|
|
->join('pricings as pr', 'd.id', '=', 'pr.service_id')
|
|
|
|
->where('d.id', '=', $domain->id)
|
|
|
|
->get(['d.*', 'pr.*']);
|
|
|
|
|
|
|
|
$labels = DB::table('labels_assigned as l')
|
|
|
|
->join('labels', 'l.label_id', '=', 'labels.id')
|
|
|
|
->where('l.service_id', '=', $domain->id)
|
|
|
|
->get(['labels.id', 'labels.label']);
|
|
|
|
|
|
|
|
return view('domains.edit', compact(['domain', 'domain_info', 'labels']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, Domains $domain)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'domain' => 'required|min:2',
|
|
|
|
'extension' => 'required|min:2',
|
|
|
|
'provider_id' => 'numeric',
|
|
|
|
'price' => 'numeric'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$pricing = new Pricing();
|
|
|
|
|
|
|
|
$as_usd = $pricing->convertToUSD($request->price, $request->currency);
|
|
|
|
|
|
|
|
DB::table('pricings')
|
|
|
|
->where('service_id', $domain->id)
|
|
|
|
->update([
|
|
|
|
'service_type' => 4,
|
|
|
|
'currency' => $request->currency,
|
|
|
|
'price' => $request->price,
|
|
|
|
'term' => $request->payment_term,
|
|
|
|
'as_usd' => $as_usd,
|
|
|
|
'usd_per_month' => $pricing->costAsPerMonth($as_usd, $request->payment_term),
|
|
|
|
'next_due_date' => $request->next_due_date,
|
|
|
|
'active' => (isset($request->is_active)) ? 1 : 0
|
|
|
|
]);
|
|
|
|
|
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);
|
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-03-05 16:58:25 +01:00
|
|
|
Cache::forget('services_count');//Main page services_count cache
|
|
|
|
Cache::forget('due_soon');//Main page due_soon cache
|
|
|
|
Cache::forget('recently_added');//Main page recently_added cache
|
|
|
|
|
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-03-05 16:58:25 +01:00
|
|
|
Cache::forget('services_count');//Main page services_count cache
|
|
|
|
Cache::forget('due_soon');//Main page due_soon cache
|
|
|
|
Cache::forget('recently_added');//Main page recently_added cache
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('domains.index')
|
|
|
|
->with('success', 'Domain was deleted Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|