add nova wizard
This commit is contained in:
90
app/Nova/Wizards/AddUserWizard.php
Normal file
90
app/Nova/Wizards/AddUserWizard.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Nova\Wizards;
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Nova\Fields\Number;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Fields\Textarea;
|
||||
use Wdelfuego\NovaWizard\AbstractWizard;
|
||||
|
||||
class AddUserWizard extends AbstractWizard
|
||||
{
|
||||
public function wizardViewData(): array
|
||||
{
|
||||
return [
|
||||
'steps' => [
|
||||
[
|
||||
'title' => 'Step 1/2',
|
||||
'fields' => [
|
||||
Text::make(__('Username'), 'username'),
|
||||
Text::make(__('Text field'), 'myText'),
|
||||
Textarea::make(__('Longer text'), 'myLongerText')
|
||||
->help("You can use Help texts on Nova fields like you're used to"),
|
||||
Number::make(__('Some number'), 'myNumber')
|
||||
->rules('required')
|
||||
->withMeta(['value' => 60])
|
||||
->min(1)
|
||||
->step(1),
|
||||
],
|
||||
],
|
||||
[
|
||||
'title' => 'Step 2/2',
|
||||
'fields' => [
|
||||
Text::make(__('Text field 2'), 'myText2'),
|
||||
Textarea::make(__('Longer text 2'), 'myLongerText2')
|
||||
->help("You can use Help texts on Nova fields like you're used to"),
|
||||
Number::make(__('Some number 2'), 'myNumber2')
|
||||
->rules('required')
|
||||
->withMeta(['value' => 60])
|
||||
->min(1)
|
||||
->step(1),
|
||||
],
|
||||
],
|
||||
[
|
||||
'title' => 'Step 2/2',
|
||||
'fields' => [
|
||||
Text::make(__('Text field 2'), 'myText2'),
|
||||
Textarea::make(__('Longer text 2'), 'myLongerText2')
|
||||
->help("You can use Help texts on Nova fields like you're used to"),
|
||||
Number::make(__('Some number 2'), 'myNumber2')
|
||||
->rules('required')
|
||||
->withMeta(['value' => 60])
|
||||
->min(1)
|
||||
->step(1),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function onSubmit($formData, &$context): bool
|
||||
{
|
||||
//
|
||||
// When this method gets called, a valid and complete wizard was submitted.
|
||||
//
|
||||
// $formData is an array that contains the data submitted by the user.
|
||||
//
|
||||
// $context is an empty array that you can store arbitrary info in;
|
||||
// it will be passed to the next method so you can use it
|
||||
// to display specific context info to the user on success.
|
||||
|
||||
// Parse submitted wizard data somehow
|
||||
$user = User::create(['name' => $formData['username']]);
|
||||
$context['newUserId'] = $user->id;
|
||||
|
||||
// Return true at the end of this method to indicate success
|
||||
return true;
|
||||
|
||||
// Or return false if the data can not be parsed successfully;
|
||||
// the user will then stay in the form view and have a chance
|
||||
// to revise the data before resubmitting.
|
||||
}
|
||||
|
||||
public function successViewData($context): array
|
||||
{
|
||||
return [
|
||||
'message' => 'Successfully created user with id: '.$context['newUserId'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user