add nova wizard
This commit is contained in:
@@ -190,7 +190,7 @@ class LoanOrder extends Resource
|
||||
// $table->text('passport_two');
|
||||
// $table->text('passport_three');
|
||||
// $table->text('passport_four');
|
||||
|
||||
|
||||
// $table->foreignId('filled_by')->constrained('users')->restrictOnDelete();
|
||||
// $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
|
||||
// $table->string('status')->index();
|
||||
|
||||
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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ use Laravel\Nova\Menu\MenuItem;
|
||||
use Laravel\Nova\Menu\MenuSection;
|
||||
use Laravel\Nova\Nova;
|
||||
use Laravel\Nova\NovaApplicationServiceProvider;
|
||||
use Wdelfuego\NovaWizard\NovaWizard;
|
||||
|
||||
class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
{
|
||||
@@ -83,6 +84,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
LocaleSwitcher::make()
|
||||
->setLocales(config('app.locales'))
|
||||
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
|
||||
// new NovaWizard('add-user'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -105,6 +107,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
|
||||
MenuSection::make(__('Orders'), [
|
||||
MenuItem::resource(LoanOrder::class),
|
||||
// MenuItem::link('Add a user', NovaWizard::pathToWizard('add-user'))
|
||||
])->icon('collection')->collapsable(),
|
||||
|
||||
MenuSection::make(__('System'), [
|
||||
|
||||
Reference in New Issue
Block a user