├── screenshots └── example.gif ├── resources └── js │ ├── tool.js │ ├── storage │ └── BelongsToFieldStorage.js │ └── components │ └── Tool.vue ├── webpack.mix.js ├── phpcs.xml ├── CHANGELOG.md ├── src └── ToolServiceProvider.php ├── LICENSE.md ├── package.json ├── composer.json └── README.md /screenshots/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebronner/nova-prepopulate-searchable/HEAD/screenshots/example.gif -------------------------------------------------------------------------------- /resources/js/tool.js: -------------------------------------------------------------------------------- 1 | import Tool from './components/Tool'; 2 | 3 | Nova.booting((Vue, router) => { 4 | Vue.component('form-belongs-to-field', Tool); 5 | }) 6 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | let mix = require('laravel-mix'); 2 | 3 | mix 4 | .js('resources/js/tool.js', 'dist/js') 5 | .webpackConfig({ 6 | resolve: { 7 | alias: { 8 | '@': path.resolve(__dirname, 'vendor/laravel/nova/resources/js/'), 9 | }, 10 | }, 11 | }) 12 | ; 13 | -------------------------------------------------------------------------------- /resources/js/storage/BelongsToFieldStorage.js: -------------------------------------------------------------------------------- 1 | export default { 2 | fetchAvailableResources(resourceName, fieldAttribute, params) { 3 | return Nova.request().get( 4 | `/nova-api/${resourceName}/associatable/${fieldAttribute}`, 5 | params 6 | ) 7 | }, 8 | 9 | determineIfSoftDeletes(resourceName) { 10 | return Nova.request().get(`/nova-api/${resourceName}/soft-deletes`) 11 | }, 12 | } 13 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | GeneaLabs coding standards. 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.3.2] - 2020-09-03 8 | ### Added 9 | - additional dependency constraints and updated readme to reflect requirements. 10 | 11 | ## [1.3.1] - 2020-09-02 12 | ### Fixed 13 | - `readonly()` method. 14 | 15 | ## [1.3.0] - 2020-09-02 16 | ### Added 17 | - inline create-related-resource link. 18 | - debounce option. 19 | -------------------------------------------------------------------------------- /src/ToolServiceProvider.php: -------------------------------------------------------------------------------- 1 | meta['prepopulate'] = true; 17 | $this->meta['prepopulate_query'] = $query; 18 | 19 | return $this; 20 | }); 21 | 22 | Nova::script( 23 | 'nova-prepopulate-searchable', 24 | __DIR__ . '/../dist/js/tool.js' 25 | ); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2020 Mike Bronner, GeneaLabs, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 7 | "prod": "npm run production", 8 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "watch-poll": "npm run watch -- --watch-poll", 10 | "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "cross-env": "^5.0.0", 14 | "laravel-mix": "^4.0", 15 | "laravel-nova": "^1.0", 16 | "vue": "^2.5.0", 17 | "vue-template-compiler": "^2.6.10" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "genealabs/nova-prepopulate-searchable", 3 | "description": "A tool to allow BelongsTo searchable fields to be pre-populated with data", 4 | "keywords": [ 5 | "laravel", 6 | "nova" 7 | ], 8 | "homepage": "https://github.com/alexbowers/nova-prepopulate-searchable", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Mike Bronner", 13 | "email": "hello@genealabs.com", 14 | "role": "Developer" 15 | }, 16 | { 17 | "name": "Alex Bowers", 18 | "email": "bowersbros@gmail.com", 19 | "role": "Original Creator" 20 | } 21 | ], 22 | "repositories": [ 23 | { 24 | "type": "composer", 25 | "url": "https://nova.laravel.com" 26 | } 27 | ], 28 | "require": { 29 | "php": "^7.4|^8.0", 30 | "laravel/nova": "^3.31", 31 | "illuminate/support": "^9.0" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "GeneaLabs\\NovaPrepopulateSearchable\\": "src/" 36 | } 37 | }, 38 | "extra": { 39 | "laravel": { 40 | "providers": [ 41 | "GeneaLabs\\NovaPrepopulateSearchable\\ToolServiceProvider" 42 | ] 43 | } 44 | }, 45 | "config": { 46 | "sort-packages": true 47 | }, 48 | "minimum-stability": "dev", 49 | "prefer-stable": true 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This package has been archived until such time that it can be brought up-to-date with Laravel Nova. We have stopped using Laravel Nova, and no longer have a license for it. As such we currently cannot justify further development on this package. Please check here for availability of similar packages: https://novapackages.com 2 | 3 | # Prepoulate Searchable for Laravel Nova 4 | **A tool to allow BelongsTo searchable fields to be pre-populated with data** 5 | 6 | [](https://packagist.org/packages/alexbowers/nova-prepopulate-searchable) 7 | [](https://packagist.org/packages/genealabs/nova-prepopulate-searchable) 8 | 9 |  10 | 11 | 12 | ```diff 13 | - Alert: the namespace of this repo has changed from `alexbowers/nova-prepopulate-searchable` 14 | - to `genealabs/nova-prepopulate-searchable`. Please update your composer.json file before updating! 15 | ``` 16 | 17 | ## Sponsors 18 | We thank the following sponsors for their generosity. Please take a moment to check them out: 19 | 20 | - [LIX](https://lix-it.com) 21 | 22 | ## Requirements 23 | - PHP 7.3+ 24 | - Laravel 7.0+ 25 | - Nova 3.8.4+ 26 | 27 | ## Installation 28 | 29 | You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer: 30 | 31 | ```bash 32 | composer require genealabs/nova-prepopulate-searchable 33 | ``` 34 | 35 | ## Usage 36 | 37 | On any `BelongsTo` fields in your resources that are `searchable()`, you can also add `prepopulate()` to the method chain and the field will be prepopulated with values to choose from. 38 | 39 | You may optionally pass through a search query to the prepopulate method, and the keywords passed will be used for 40 | the search initially, before resetting the search to being empty (as it currently is). 41 | 42 | ### Limiting Pre-Populated Items 43 | You can limit the prepopulated items by passing in a search string to the `prepopulated()` method like so: 44 | 45 | ```php 46 | BelongsTo::make("Archive") 47 | ->searchable() 48 | ->prepopulate("test"). 49 | ``` 50 | 51 | This would prepopulate all archives that have test in their display field. 52 | 53 | ### Security 54 | 55 | If you discover any security related issues, please email hello@genealabs.com instead of using the issue tracker. 56 | 57 | ## Credits 58 | 59 | ### [Alex Bowers](https://github.com/alexbowers) 60 | 61 | Alex is the original developer of this package and has done a great job with initial development. 62 | 63 | ### [Mike Bronner](https://github.com/mikebronner) 64 | 65 | I started using this package and didn't want it to fall to the way-side, as it helps improve the UX of Nova significantly. Alex graceously allowed me to continue development and maintenance on his original package. 66 | 67 | ## License 68 | 69 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 70 | -------------------------------------------------------------------------------- /resources/js/components/Tool.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 25 | 29 | 33 | 34 | 35 | {{ selectedResource.display }} 36 | 37 | 38 | 43 | 47 | 51 | 52 | 53 | 54 | 58 | {{ option.display }} 59 | 60 | 61 | 66 | {{ option.subtitle }} 67 | {{ __('No additional information...') }} 68 | 69 | 70 | 71 | 72 | 73 | 85 | 90 | {{ placeholder }} 91 | 92 | 93 | 94 | 99 | 100 | 101 | 102 | 113 | 114 | 115 | 116 | 120 | 125 | {{ __('With Trashed') }} 126 | 127 | 128 | 129 | 130 | 131 | 132 | 433 | --------------------------------------------------------------------------------