Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yassilah/nova-custom-form
Allows you to define entirely customizable components for specific Nova Resources
https://github.com/yassilah/nova-custom-form
Last synced: about 1 month ago
JSON representation
Allows you to define entirely customizable components for specific Nova Resources
- Host: GitHub
- URL: https://github.com/yassilah/nova-custom-form
- Owner: yassilah
- Created: 2018-09-24T07:46:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-12T16:33:34.000Z (over 5 years ago)
- Last Synced: 2024-04-06T04:02:58.962Z (9 months ago)
- Language: PHP
- Size: 46.9 KB
- Stars: 7
- Watchers: 4
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nova Custom Form
This package allows you to define entirely customizable components for specific Nova Resources.# Installation
```
composer require yassi/nova-custom-form
```Then you need to add the service provider to your config/app.php **after the NovaServiceProvider**:
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/'providers' => [
...
App\Providers\NovaServiceProvider::class,
...
Yassi\NovaCustomForm\NovaCustomFormServiceProvider::class,
...Once installed and registered, simply add the CustomFormTrait to your App\Nova\Resource:
namespace App\Nova;use Laravel\Nova\Resource as NovaResource;
use Laravel\Nova\Http\Requests\NovaRequest;
use Yassi\NovaCustomForm\CustomFormTrait;abstract class Resource extends NovaResource
{
use CustomFormTrait;
...# Create a new form
This is exactly the same process as for any other Nova Tool, ResourceTool or Field. You can simply use that command in your terminal:```
php artisan nova:form @vendor/package-name
```This will create your form component in /nova-components/PackageName. If you've installed the dependencies during the previous process, you can directly go ahead and use:
```
cd /nova-components/PackageName && yarn watch
```You can modify the Create and Edit components inside /nova-components/PackageName/resources/js/components as you like :)
# Attach a new form to a resource
The CustomFormTrait adds a static method "form" to your resources and passes the current request as an argument. By default, that function returns null, meaning it will use the default Nova form. You just need to override that function and return a new instance of your custom form.
namespace App\Nova;use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\Password;
use Vendor\PackageName\PackageName;class User extends Resource
{
...
/**
* This method registers the custom form
* to be used for the User resource.
*
* @return PackageName
*/
public static function form ($request) {
return new PackageName;
}
You can specify which user or which type of user get access to this custom form:
```
public static function form ($request) {
return $request->user()->email === '[email protected]' ? new PackageName : null;
}
```