new request, preparing support_url for validation

This commit is contained in:
akemidx 2023-04-20 16:34:25 -04:00
parent 0a993b2aa1
commit 16a5a883e5
4 changed files with 59 additions and 3 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Http\Requests\ImageUploadRequest;
use App\Http\Requests\SaveManufacturerRequest;
use App\Models\Manufacturer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -114,7 +115,7 @@ class ManufacturersController extends Controller
* @since [v1.0]
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function update(ImageUploadRequest $request, $manufacturerId = null)
public function update(SaveManufacturerRequest $request, $manufacturerId = null)
{
$this->authorize('update', Manufacturer::class);
// Check if the manufacturer exists

View file

@ -0,0 +1,41 @@
<?php
namespace App\Http\Requests;
use App\Models\Manufacturer;
class SaveManufacturerRequest extends ImageUploadRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return parent::rules() + (new Manufacturer())->getRules();
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'support_url' => $this->input('support_url'),
]);
dd($this->all());
}
}

View file

@ -534,6 +534,20 @@ class AssetPresenter extends Presenter
return false;
}
/**
* Used to take user created warranty URL and dynamically fill in the needed values per asset
* @return string
*/
public function supportUrl()
{
$tempurl = $this->model->model->manufacturer->support_url;
$tempurl = (str_replace('{LOCALE}',\App\Models\Setting::getSettings()->locale,$tempurl));
$tempurl = (str_replace('{SERIAL}',$this->model->serial,$tempurl));
return $tempurl;
}
/**
* Url to view this item.
* @return string

View file

@ -596,7 +596,7 @@
{{ trans('admin/hardware/form.months') }}
@if ($asset->serial && $asset->model->manufacturer)
<a href="{{ (str_replace('_testlocale_',\App\Models\Setting::getSettings()->locale,$asset->model->manufacturer->support_url))}}" target="_blank">
<a href="{{ $asset->present()->supportUrl() }}" target="_blank">
<i class="fa fa-external-link" style="width:25px;height:25px;"><span class="sr-only">{{ trans('hardware/general.mfg_warranty_lookup') }}</span></i>
</a>
@endif