https://github.com/alitnk/nova-parental-field
A Laravel Nova field made for Parental to quickly make a select element to choose the child type
https://github.com/alitnk/nova-parental-field
laravel laravel-nova nova parental single-table-inheritance
Last synced: 2 months ago
JSON representation
A Laravel Nova field made for Parental to quickly make a select element to choose the child type
- Host: GitHub
- URL: https://github.com/alitnk/nova-parental-field
- Owner: alitnk
- License: mit
- Created: 2021-07-07T18:23:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-16T04:58:50.000Z (over 3 years ago)
- Last Synced: 2025-03-24T20:12:54.487Z (3 months ago)
- Topics: laravel, laravel-nova, nova, parental, single-table-inheritance
- Language: PHP
- Homepage:
- Size: 161 KB
- Stars: 5
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nova Parental Field
A Laravel Nova field made for [Parental](https://github.com/calebporzio/parental) to quickly make a select element to choose the child type## Installation
```bash
composer require alitnk/nova-parental-field
```## Usage
```php
use Wama\NovaParentalField\Parental;public function fields(Request $request)
{
return [
// ... your other fields
Parental::make()->searchable(),
];
}
```
The parental field extends Nova's select field. so you can make use of methods like `searchable()` on it.Passing the field's name is optional, the package will automatically get the field name based on your `$childColumn` property and if there is none, [it'll just default to `type`](https://github.com/calebporzio/parental/blob/a0739736b9a34cb78bca5b4eda45882765644ff5/src/HasChildren.php#L174).
After making the field, it automatically gets the children types and populates them in the select field.
---
So, assuming your parent model looks like this:
```php
class User extends Model {
use HasChildren;private $childTypes = [
'admin' => Admin::class,
'moderator' => Moderator::class,
'author' => Author::class,
];
}
```
After you add the `Parental::make()->searchable()` to your Nova fields, you should get the following result: