From 392136dc9b8f605b908ee774dea9b0ca0420ef60 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Fri, 24 Nov 2023 21:19:50 +0500 Subject: [PATCH] add nova wizard --- app/Nova/Resources/Order/Loan/LoanOrder.php | 2 +- app/Nova/Wizards/AddUserWizard.php | 90 +++++++++++++++++++++ app/Providers/NovaServiceProvider.php | 3 + composer.json | 3 +- composer.lock | 53 +++++++++++- config/nova-wizard.php | 46 +++++++++++ 6 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 app/Nova/Wizards/AddUserWizard.php create mode 100644 config/nova-wizard.php diff --git a/app/Nova/Resources/Order/Loan/LoanOrder.php b/app/Nova/Resources/Order/Loan/LoanOrder.php index 19a452b..9899c7b 100644 --- a/app/Nova/Resources/Order/Loan/LoanOrder.php +++ b/app/Nova/Resources/Order/Loan/LoanOrder.php @@ -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(); diff --git a/app/Nova/Wizards/AddUserWizard.php b/app/Nova/Wizards/AddUserWizard.php new file mode 100644 index 0000000..5782c36 --- /dev/null +++ b/app/Nova/Wizards/AddUserWizard.php @@ -0,0 +1,90 @@ + [ + [ + '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'], + ]; + } +} diff --git a/app/Providers/NovaServiceProvider.php b/app/Providers/NovaServiceProvider.php index e1c4158..cebd860 100644 --- a/app/Providers/NovaServiceProvider.php +++ b/app/Providers/NovaServiceProvider.php @@ -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'), [ diff --git a/composer.json b/composer.json index 2d0a4ff..bfd69b9 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "outl1ne/nova-translatable": "^2.2", "spatie/laravel-permission": "^6.1", "spatie/laravel-translatable": "^6.5", - "trin4ik/nova-switcher": "^0.4.0" + "trin4ik/nova-switcher": "^0.4.0", + "wdelfuego/nova-wizard": "^1.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 27e28dd..848b2b4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "77a24bc6798fc44d2104306518b27e22", + "content-hash": "e54517769c07296164429fd898ff3555", "packages": [ { "name": "brick/math", @@ -7071,6 +7071,57 @@ ], "time": "2022-03-08T17:03:00+00:00" }, + { + "name": "wdelfuego/nova-wizard", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/wdelfuego/nova-wizard.git", + "reference": "4e8879415a417f10554a69e3214acd2fb8599c1f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wdelfuego/nova-wizard/zipball/4e8879415a417f10554a69e3214acd2fb8599c1f", + "reference": "4e8879415a417f10554a69e3214acd2fb8599c1f", + "shasum": "" + }, + "require": { + "laravel/nova": "^4.0", + "php": "^7.3|^8.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Wdelfuego\\NovaWizard\\ToolServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Wdelfuego\\NovaWizard\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later", + "proprietary" + ], + "description": "A tool to create wizards in Nova 4.", + "keywords": [ + "form", + "laravel", + "multi step", + "multistep", + "nova", + "wizard" + ], + "support": { + "issues": "https://github.com/wdelfuego/nova-wizard/issues", + "source": "https://github.com/wdelfuego/nova-wizard/tree/v1.0.1" + }, + "time": "2023-10-17T13:18:08+00:00" + }, { "name": "webmozart/assert", "version": "1.11.0", diff --git a/config/nova-wizard.php b/config/nova-wizard.php new file mode 100644 index 0000000..2a75464 --- /dev/null +++ b/config/nova-wizard.php @@ -0,0 +1,46 @@ + [ + + /* + * The class of the Nova Wizard. + Don't forget to add the proper use statement above. + This key is required. + */ + 'class' => AddUserWizard::class, + + /* + * URI for this wizard (will be appended to the Nova path, /nova by default) + This key is required. + */ + 'uri' => 'wizard/add-user', + + /* + * Browser window/tab title for this Nova Wizard. + This key is optional. + If you remove it or set it to an empty string, the dynamic title displayed above + the wizard view will be used as window/tab title in the browser. + */ + 'windowTitle' => 'Add User', + + ], + +];