No longer need to test for type, it should exist

This commit is contained in:
Deon George 2023-05-03 23:41:48 +10:00
parent 25dab73a83
commit a5238bfbdc
6 changed files with 19 additions and 8 deletions

View File

@ -44,6 +44,14 @@ class ProductController extends Controller
->sortBy('name') ->sortBy('name')
->values(); ->values();
case 'App\Models\Product\Generic':
return Product\Generic::select(['id','supplier_item_id'])
->with(['supplied.supplier_detail.supplier'])
->get()
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier_detail->supplier->name,$item->supplied->name)]; })
->sortBy('name')
->values();
case 'App\Models\Product\Host': case 'App\Models\Product\Host':
return Product\Host::select(['id','supplier_item_id']) return Product\Host::select(['id','supplier_item_id'])
->with(['supplied.supplier_detail.supplier']) ->with(['supplied.supplier_detail.supplier'])

View File

@ -294,7 +294,7 @@ class Product extends Model implements IDs
*/ */
public function getSuppliedAttribute(): ?Model public function getSuppliedAttribute(): ?Model
{ {
return $this->type && $this->type->supplied ? $this->type->supplied : NULL; return $this->type->supplied ? $this->type->supplied : NULL;
} }
/** /**
@ -426,7 +426,7 @@ class Product extends Model implements IDs
*/ */
public function hasUsage(): bool public function hasUsage(): bool
{ {
return $this->type && $this->type->hasUsage(); return $this->type->hasUsage();
} }
/** /**

View File

@ -786,7 +786,7 @@ class Service extends Model implements IDs
*/ */
public function getNameShortAttribute() public function getNameShortAttribute()
{ {
return ($this->type && $this->type->getServiceNameAttribute()) ? $this->type->getServiceNameAttribute() : 'SID:'.$this->sid; return $this->type->getServiceNameAttribute() ? $this->type->getServiceNameAttribute() : 'SID:'.$this->sid;
} }
/** /**
@ -801,7 +801,7 @@ class Service extends Model implements IDs
*/ */
public function getNameDetailAttribute() public function getNameDetailAttribute()
{ {
return ($this->type && ($this->type->getServiceDescriptionAttribute() !== NULL)) ? $this->type->getServiceDescriptionAttribute() : 'No Description'; return ($this->type->getServiceDescriptionAttribute() !== NULL) ? $this->type->getServiceDescriptionAttribute() : 'No Description';
} }
/** /**

View File

@ -45,10 +45,11 @@ class SSL extends Type
if ($this->cert) if ($this->cert)
return Arr::get($this->crt_parse,'name'); return Arr::get($this->crt_parse,'name');
else { elseif ($this->csr) {
$dn = ''; $dn = '';
$dna = openssl_csr_get_subject($this->csr); $dna = openssl_csr_get_subject($this->csr);
dump(['dna'=>$dna,'csr'=>$this->csr,'id',$this->id]);
foreach ($dna as $k=>$v) { foreach ($dna as $k=>$v) {
if ($dn) if ($dn)
$dn .= ','; $dn .= ',';
@ -57,6 +58,8 @@ class SSL extends Type
} }
return $dn; return $dn;
} else {
return '[NO DN]';
} }
} }

View File

@ -3,7 +3,7 @@
<div class="col-12"> <div class="col-12">
<h3>Product Details @include('adminlte::widget.success_button')</h3> <h3>Product Details @include('adminlte::widget.success_button')</h3>
<hr> <hr>
@dump($errors)
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form"> <form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
@csrf @csrf
@ -75,7 +75,7 @@
'old'=>'model', 'old'=>'model',
'name'=>'model', 'name'=>'model',
'options'=>$o->availableTypes()->transform(function($item) { return ['id'=>$item,'value'=>$item]; }), 'options'=>$o->availableTypes()->transform(function($item) { return ['id'=>$item,'value'=>$item]; }),
'value'=>($o->type && $x=get_class($o->type)) ? $x : '', 'value'=>get_class($o->type),
]) ])
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@
@php @php
$po = $selected = NULL; $po = $selected = NULL;
@endphp @endphp
@foreach (\App\Models\Product::active()->get()->filter(function($item) { return $item->type && (get_class($item->type) == 'App\Models\Product\Broadband'); })->sortBy('name') as $o) @foreach (\App\Models\Product::active()->get()->filter(function($item) { return get_class($item->type) === 'App\Models\Product\Broadband'; })->sortBy('name') as $o)
@php @php
if ($o->id == old('product_id')) { if ($o->id == old('product_id')) {
$selected = 'selected'; $selected = 'selected';