You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
process information in the uploaded (Get the list of variables in the word template file)
Gather more information
Summary - display, file name and some information from step 3
when 'submit' on the summary page is pressed, I would like to save the uploaded file to a specific location and add the gathered information to a new record in the database.
When I press 'Next' in step 2 (file upload) I can see that the file is 'uploaded' to the Livewire tmp folder, but if I press back the uploaded file is 'lost'
The uploaded file is not stored on a model, but on a property on the main component, or at least that is what I am trying to do.
Here is the code:
Wizard
<?php
namespace App\Http\Livewire;
use App\Classes\WizardSteps\DocTemplate\Greeting;
use App\Classes\WizardSteps\DocTemplate\Summary;
use App\Classes\WizardSteps\DocTemplate\TemplateFields;
use App\Classes\WizardSteps\DocTemplate\TemplateFieldsValues;
use App\Classes\WizardSteps\DocTemplate\UploadTemplate;
use App\Models\User;
use Livewire\WithFileUploads;
use Vildanbina\LivewireWizard\WizardComponent;
class UserDocTemplateWizard extends WizardComponent
{
use WithFileUploads;
public array $steps = [
Greeting::class,
UploadTemplate::class,
TemplateFields::class,
TemplateFieldsValues::class,
Summary::class,
];
// My custom class property
public $userId;
public $template_name;
public $template_file;
public $template_fields;
public $template_fields_values;
public function model(): array|User
{
// This model is mostly used to display users name in the
// greeting step and is needed at the end to link the uploaded
// file and the information gathered to the user
return User::findOrNew($this->userId);
}
}
Step 1
<?php
namespace App\Classes\WizardSteps\DocTemplate;
use Vildanbina\LivewireWizard\Components\Step;
class Greeting extends Step
{
protected string $view = 'wizards.steps.doc-template.general';
public function mount(): void
{
}
public function icon(): string
{
return 'check';
}
public function save($state): void
{
}
public function validate(): array
{
return [
];
}
public function title(): string
{
return __('Greeting');
}
}
Step 2
<?php
namespace App\Classes\WizardSteps\DocTemplate;
use Vildanbina\LivewireWizard\Components\Step;
class UploadTemplate extends Step
{
protected string $view = 'wizards.steps.doc-template.upload-template';
public string $template_name = '';
public $template_file = '';
public function title(): string
{
return 'Upload Template';
}
public function mount()
{
$this->mergeState([
'template_file' => $this->getLivewire()->template_file,
'template_name' => $this->getLivewire()->template_name,
]);
}
public function save($state)
{
$state['template_file']->store('template_file');
$state['template_name'] = $this->template_name;
}
public function validate(): array
{
return [
[
'state.template_file' => 'max:1024',
],
];
}
}
Step 3
<?php
namespace App\Classes\WizardSteps\DocTemplate;
use Vildanbina\LivewireWizard\Components\Step;
class TemplateFields extends Step
{
protected string $view = 'wizards.steps.doc-template.template-fields';
public array $template_fields;
public function mount(): void
{
$this->mergeState([
'template_fields' => $this->getLivewire()->template_fields,
]);
}
public function icon(): string
{
return 'check';
}
public function save($state)
{
$state['template_fields'] = $this->template_fields;
}
public function validate(): array
{
return [
];
}
public function title(): string
{
return 'Template fields';
}
}
Step 4
<?php
namespace App\Classes\WizardSteps\DocTemplate;
use Vildanbina\LivewireWizard\Components\Step;
class TemplateFieldsValues extends Step
{
protected string $view = 'wizards.steps.doc-template.template-fields';
public function mount(): void
{
}
public function icon(): string
{
return 'check';
}
public function save($state): void
{
$state['template_fields'] = $this->template_fields;
}
public function validate(): array
{
return [
];
}
public function title(): string
{
return 'Template fields values';
}
}
Step 5
<?php
namespace App\Classes\WizardSteps\DocTemplate;
use Vildanbina\LivewireWizard\Components\Step;
class Summary extends Step
{
protected string $view = 'wizards.steps.doc-template.summary';
public function mount(): void
{
}
public function icon(): string
{
return 'check';
}
public function save($state): void
{
}
public function validate(): array
{
return [
];
}
public function title(): string
{
return 'Summary';
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
I have a wizard with 5 steps:
when 'submit' on the summary page is pressed, I would like to save the uploaded file to a specific location and add the gathered information to a new record in the database.
When I press 'Next' in step 2 (file upload) I can see that the file is 'uploaded' to the Livewire tmp folder, but if I press back the uploaded file is 'lost'
The uploaded file is not stored on a model, but on a property on the main component, or at least that is what I am trying to do.
Here is the code:
Wizard
Step 1
Step 2
Step 3
Step 4
Step 5
Beta Was this translation helpful? Give feedback.
All reactions