F
Filament7mo ago
Noor

Data is not getting saved in db after tranferring one form data to another

What would be the right approach to promote prospect to lead , I have a action on prospect 'promote to lead' and parameters on prospect are promoteLead_on and promoteLead_by so when I click on action it goes to lead form and when I save it , it is not getting saved in database. I want promoteLead_on and promoteLead_by after saving the lead form or when I click action . ViewProspect
Actions\Action::make('promoteLead')
->label('Promote To Lead')
->url(function (): string {
return route('filament.app.resources.leads.create', [
'business_name' => $this->record->business_name,
'contact_name' => $this->record->contact_name,
'phone' => $this->record->phone,
'email' => $this->record->email,
'promoteLead_on' => Carbon::now()->toDateTimeString(),
'promoteLead_by' => Auth::id(),
]);
})
Actions\Action::make('promoteLead')
->label('Promote To Lead')
->url(function (): string {
return route('filament.app.resources.leads.create', [
'business_name' => $this->record->business_name,
'contact_name' => $this->record->contact_name,
'phone' => $this->record->phone,
'email' => $this->record->email,
'promoteLead_on' => Carbon::now()->toDateTimeString(),
'promoteLead_by' => Auth::id(),
]);
})
CreateLead
protected function afterFill(): void
{
$promotedOn = Carbon::now();
$promotedBy = Auth::id();

$contactName = request()->query('contact_name');

$nameParts = explode(" ", $contactName);
if (count($nameParts) === 2) {
list($firstName, $lastName) = explode(" ", $contactName);
} else {
$firstName = $contactName;
$lastName = "";
}

$this->data['business_name'] = request()->query('business_name');
$this->data['first_name'] = $firstName;
$this->data['last_name'] = $lastName;
$this->data['phone'] = request()->query('phone');
$this->data['email'] = request()->query('email');

$this->data['promoteLead_on'] = request()->query('promoteLead_on');
$this->data['promoteLead_by'] = request()->query('promoteLead_by');
}
protected function afterFill(): void
{
$promotedOn = Carbon::now();
$promotedBy = Auth::id();

$contactName = request()->query('contact_name');

$nameParts = explode(" ", $contactName);
if (count($nameParts) === 2) {
list($firstName, $lastName) = explode(" ", $contactName);
} else {
$firstName = $contactName;
$lastName = "";
}

$this->data['business_name'] = request()->query('business_name');
$this->data['first_name'] = $firstName;
$this->data['last_name'] = $lastName;
$this->data['phone'] = request()->query('phone');
$this->data['email'] = request()->query('email');

$this->data['promoteLead_on'] = request()->query('promoteLead_on');
$this->data['promoteLead_by'] = request()->query('promoteLead_by');
}
2 Replies
Noor
NoorOP7mo ago
:squint: Any solution or idea please ?
Tieme
Tieme7mo ago
Hi, first a sidenote, please don't use route when creating a url to a resource. Read the following https://filamentphp.com/docs/3.x/panels/resources/getting-started#generating-urls-to-resource-pages Are you getting any errors? Is your form populated with all the data you want? Because what you are doing is not changing data before safe you need to use https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving for that. Your action is before filling the form, so is the form populated with data?
Want results from more Discord servers?
Add your server