Closed swarakaka closed 2 years ago
May I see your full component please.
Yes, please :
<?php
namespace App\Http\Livewire\Forms\Companies;
use App\Models\Company;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Spatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia;
use Tanthammar\TallForms\Checkbox;
use Tanthammar\TallForms\ImageCropper;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\TallFormComponent;
use Tanthammar\TallFormsSponsors\Email;
use Tanthammar\TallFormsSponsors\Tel;
class CreateOrUpdateCompany extends TallFormComponent
{
public Collection $breads;
public string $backButton = 'companies';
public string $formTitle = '';
public function mount(?Company $company)
{
$this->formTitle = $company->exists ?
__('Edit :item ', ['item'=> $company->name])
: __('Add :model ', ['model'=> __('Company')]);
$this->breads = new Collection([
['text'=> __('Companies'), 'url'=> 'companies'],
['text'=> __($this->formTitle)],
]);
//Gate::authorize()
$this->mount_form($company); // $company from hereon, called $this->model
}
protected function formAttr(): array
{
return [
'wrapWithView' => true,
'showDelete' => false,
'showReset' => !$this->model->exists,
];
}
// OPTIONAL methods, they already exist
protected function onCreateModel($validated_data)
{
$this->model = Company::create($validated_data);
}
protected function onUpdateModel($validated_data)
{
$this->model->update($validated_data);
}
protected function onDeleteModel()
{
$this->defaultDelete();
}
protected function fields(): array
{
return [
Checkbox::make(__('Allow Email Empty?'),'email_empty')
->default(false)
->rules('boolean')
->hideLabel(),
Input::make(__('Name'), 'name')
->rules($this->model->exists
? ['required', 'max:255', Rule::unique('companies','name')->ignore($this->model->id)]
:['required', 'max:255', Rule::unique('companies','name')])
->autocomplete("new-name")
->colspan(6),
Input::make(__('Code'),'code')
->rules($this->model->exists
?['required', 'max:255', Rule::unique('companies','code')->ignore($this->model->id)]
:['required', 'max:255', Rule::unique('companies','code')])
->autocomplete("new-code")
->colspan(6),
Tel::make(__('Phone'),'phone')
->autocomplete("new-phone")
->rules(['required','digits_between:11,14'])
->colspan(6),
Input::make(__('Phone owner'),'phone_owner')
->autocomplete("new-phone-owner")
->rules('required')
->colspan(6),
Email::make(__('Email'),'email')
->rules('required_if:form_data.email_empty,false')
->autocomplete("new-email")
->colspan(6),
Input::make(__('Address'),'address')
->autocomplete("new-address")
->rules('nullable')
->colspan(6),
];
}
protected function saveAndGoBackResponse()
{
$this->withSession()->notify('success','The form was saved successfully');
return redirect()->route('companies');
}
}
Thank you for reporting. Please upgrade to v8.2.4
It working perfect, thank you.
If notifications are in session, they will be shown empty, and will be repeated four times.
$this->withSession()->notify('success','The form was saved successfully');