Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created February 2, 2021 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jongravois/60394daf8621e3ef53fe797d4b1072e0 to your computer and use it in GitHub Desktop.
Save jongravois/60394daf8621e3ef53fe797d4b1072e0 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Customers;
use App\Models\Company;
use App\Models\CompanyCustomerAgreement;
use App\Models\Country;
use App\Models\State;
use Livewire\Component;
class CompanyInfo extends Component
{
public $companyCode;
public $company;
public $countries;
public $states;
protected $rules = [
'company.legal_name' => 'required',
'company.address' => 'required',
'company.country' => 'required',
'company.address2' => 'nullable',
'company.address3' => 'nullable', //'required_if:company.country,!=,US',
'company.cage' => 'nullable',
'company.city' => 'nullable', //'required_if:company.country,==,US',
'company.dba' => 'nullable',
'company.email' => 'nullable',
'company.fax' => 'nullable',
'company.naics' => 'nullable',
'company.phone' => 'nullable',
'company.state' => 'nullable', //'required_if:company.country,==,US',
'company.uri' => 'nullable',
'company.zip' => 'nullable', //'required_if:company.country,==,US',
];
public function mount($code):void
{
$this->companyCode = $code;
$this->company = Company::whereCompanyCode($this->companyCode)->firstOrCreate();
$this->countries = Country::select('id', 'iso', 'country')->orderBy('country')->get();
$this->states = State::orderBy('state')->get();
} // end function
public function render()
{
return view('livewire.customers.company-info');
} // end function
public function saveAndAdvance(): void
{
$this->validate();
$this->company->save();
$this->emit('setStep', 3);
} // end function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment