Updated Domains controller

Cleaned up, Moved DB calls to model
This commit is contained in:
cp6 2022-05-15 16:22:47 +10:00
parent a054e83d1e
commit 6d1cbef740
2 changed files with 33 additions and 25 deletions

View File

@ -16,35 +16,22 @@ class DomainsController extends Controller
public function index() public function index()
{ {
$domains = DB::table('domains as d') $domains = Domains::domainsDataIndexPage();
->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'])); return view('domains.index', compact(['domains']));
} }
public function show(Domains $domain) public function show(Domains $domain)
{ {
$service_extras = Domains::domainsDataShowPage($domain->id);
$service_extras = DB::table('domains as d') $labels = Labels::labelsForService($domain->id);
->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.*']);
$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'])); return view('domains.show', compact(['domain', 'service_extras', 'labels']));
} }
public function create() public function create()
{ {
$Providers = Providers::allProviders(); return view('domains.create');
return view('domains.create', compact('Providers'));
} }
public function store(Request $request) public function store(Request $request)
@ -88,15 +75,9 @@ class DomainsController extends Controller
public function edit(Domains $domain) public function edit(Domains $domain)
{ {
$domain_info = DB::table('domains as d') $domain_info = Domains::domainsDataEditPage($domain->id);
->join('pricings as pr', 'd.id', '=', 'pr.service_id')
->where('d.id', '=', $domain->id)
->get(['d.*', 'pr.*']);
$labels = DB::table('labels_assigned as l') $labels = Labels::labelsForService($domain->id);
->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'])); return view('domains.edit', compact(['domain', 'domain_info', 'labels']));
} }
@ -131,6 +112,7 @@ class DomainsController extends Controller
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain->id); Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $domain->id);
Cache::forget("labels_for_service.{$domain->id}");
Cache::forget('services_count');//Main page services_count cache Cache::forget('services_count');//Main page services_count cache
Cache::forget('due_soon');//Main page due_soon cache Cache::forget('due_soon');//Main page due_soon cache
Cache::forget('recently_added');//Main page recently_added cache Cache::forget('recently_added');//Main page recently_added cache

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Domains extends Model class Domains extends Model
{ {
@ -12,4 +13,29 @@ class Domains extends Model
public $incrementing = false; public $incrementing = false;
protected $fillable = ['id', 'domain', 'extension', 'ns1', 'ns2', 'ns3', 'price', 'currency', 'payment_term', 'owned_since', 'provider_id', 'next_due_date']; protected $fillable = ['id', 'domain', 'extension', 'ns1', 'ns2', 'ns3', 'price', 'currency', 'payment_term', 'owned_since', 'provider_id', 'next_due_date'];
public static function domainsDataIndexPage()
{
return 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.*']);
}
public static function domainsDataShowPage(string $domain_id)
{
return 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.*']);
}
public static function domainsDataEditPage(string $domain_id)
{
return DB::table('domains as d')
->join('pricings as pr', 'd.id', '=', 'pr.service_id')
->where('d.id', '=', $domain_id)
->get(['d.*', 'pr.*']);
}
} }