-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eace54
commit cf94b16
Showing
26 changed files
with
1,839 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,10 @@ | ||
/vendor/ | ||
node_modules/ | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# Laravel 4 specific | ||
bootstrap/compiled.php | ||
app/storage/ | ||
|
||
# Laravel 5 & Lumen specific | ||
public/storage | ||
public/hot | ||
|
||
# Laravel 5 & Lumen specific with changed public path | ||
public_html/storage | ||
public_html/hot | ||
|
||
storage/*.key | ||
.env | ||
Homestead.yaml | ||
Homestead.json | ||
/.vagrant | ||
/.idea | ||
/vendor | ||
/node_modules | ||
package-lock.json | ||
composer.phar | ||
composer.lock | ||
phpunit.xml | ||
.phpunit.result.cache | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version 0.1.0 (2020-02-04) | ||
----------------------------- | ||
### INITED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 armincms | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,116 @@ | ||
# belongs-to-many | ||
The inline `BelongsToMany` and `MorphedByMany` field for the Laravel Nova | ||
# BelongsToMany | ||
A Laravel Nova field for `simple` and `polymorphic` `ManyToMany` relationships. | ||
|
||
##### Table of Contents | ||
* [Features](#features) | ||
* [Install](#install) | ||
* [Simple Usage](#simple-usage) | ||
* [Pivots](#pivots) | ||
* [Duplicate Attachment](#duplicate-attachment) | ||
* [Polymorphic Relation](#polymorphic-relation) | ||
|
||
|
||
## Features | ||
- Attach polymorphic and non-polymorphic `ManyToMany` relationships in | ||
the creation and update page | ||
- Edit pivot columns when attaching relation | ||
- Attach a source to another resource many times | ||
|
||
## Install | ||
```bash | ||
composer require armincms/belongs-to-many | ||
``` | ||
|
||
## Simple Usage | ||
|
||
``` | ||
use Armincms\Fields\BelongsToMany; | ||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function fields(Request $request) | ||
{ | ||
return [ | ||
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class) | ||
->fields(function() { | ||
return [ | ||
Text::make('Price') | ||
->rules('required', 'numeric'), | ||
]; | ||
}) | ||
->pivots(), | ||
]; | ||
} | ||
``` | ||
|
||
## Pivots | ||
For customizing the pivot columns when attaching a resource you can use the `pivots` method of the field. then define your custom pivot fields with the `fields` method. now, when attaching a resource; a Modal that contains the pivot fields will be displayed to you. | ||
|
||
|
||
``` | ||
use Armincms\Fields\BelongsToMany; | ||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function fields(Request $request) | ||
{ | ||
return [ | ||
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class) | ||
->fields(function() { | ||
return [ | ||
Text::make('Price') | ||
->rules('required', 'numeric'), | ||
]; | ||
}) | ||
->pivots(), | ||
]; | ||
} | ||
``` | ||
|
||
## Duplicate Attachment | ||
You can use the `duplicate` feature for repetitively attach a resource to another resource. follow the example: | ||
|
||
|
||
|
||
``` | ||
use Armincms\Fields\BelongsToMany; | ||
/** | ||
* Get the fields displayed by the resource. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function fields(Request $request) | ||
{ | ||
return [ | ||
BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class) | ||
->fields(function() { | ||
return [ | ||
Text::make('Price') | ||
->rules('required', 'numeric'), | ||
]; | ||
}) | ||
->duplicate(), | ||
]; | ||
} | ||
``` | ||
## Polymorphic Relation | ||
Using for the polymorphic relationships is like non-polymorphic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "armincms/belongs-to-many", | ||
"description": "A Laravel Nova field.", | ||
"keywords": [ | ||
"laravel", | ||
"nova" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Armincms\\Fields\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Armincms\\Fields\\FieldServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"/js/field.js": "/js/field.js", | ||
"/css/field.css": "/css/field.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"dev": "npm run development", | ||
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", | ||
"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", | ||
"watch-poll": "npm run watch -- --watch-poll", | ||
"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", | ||
"prod": "npm run production", | ||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" | ||
}, | ||
"devDependencies": { | ||
"cross-env": "^5.0.0", | ||
"laravel-mix": "^1.0", | ||
"laravel-nova": "^1.0", | ||
"@johmun/vue-tags-input": "2.0.*" | ||
}, | ||
"dependencies": { | ||
"vue": "^2.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<template> | ||
<panel-item :field="field"> | ||
<template slot="value" v-if="field.value && field.value.length"> | ||
<span v-if="field.pivots"> | ||
<span | ||
class="no-underline font-bold dim text-primary cursor-pointer" | ||
v-for="(resource, index) in field.value" | ||
:key="resource.id" | ||
@click="displayPivots(resource)" | ||
:title="__(':resource Details', { resource: resource.text })" | ||
> | ||
{{ resource.text }} {{ field.value.length - index - 1 ? ' , ' : '' }} | ||
</span> | ||
</span> | ||
<span v-else> | ||
<router-link | ||
v-for="(resource, index) in field.value" | ||
:key="index" | ||
:to="{ | ||
name: 'detail', | ||
params: { | ||
resourceName: field.resourceName, | ||
resourceId: resource.id, | ||
}, | ||
}" | ||
class="no-underline font-bold dim text-primary" | ||
:title="__('View')" | ||
> | ||
{{ resource.text }} {{ field.value.length - index - 1 ? ' , ' : '' }} | ||
</router-link> | ||
</span> | ||
<modal v-if="field.pivots && display" role="dialog" @modal-close="handleClose"> | ||
<loading-view :loading="loading"> | ||
<card :class="'w-action-fields'"> | ||
<form-heading-field | ||
:field="{ | ||
asHtml: true, | ||
value: display.text | ||
}" | ||
class="mb-6 pt-6" | ||
/> | ||
|
||
<div class="mb-6 py-3 px-6"> | ||
<!-- Pivot Fields --> | ||
<component | ||
v-for="(field, index) in fields" | ||
:key="index" | ||
:is="'detail-' + field.component" | ||
:resource-name="resourceName" | ||
:field="field" | ||
:via-resource="viaResource" | ||
:via-resource-id="viaResourceId" | ||
:via-relationship="viaRelationship" | ||
/> | ||
</div> | ||
|
||
<div class="px-6 py-3 flex"> | ||
<div class="flex items-center ml-auto"> | ||
<button | ||
class="btn btn-link dim cursor-pointer text-80 ml-auto mr-6" | ||
type="button" | ||
@click.prevent="handleClose">{{ | ||
__("Close") | ||
}}</button> | ||
<router-link | ||
:to="{ | ||
name: 'detail', | ||
params: { | ||
resourceName: field.resourceName, | ||
resourceId: display.id, | ||
}, | ||
}" | ||
class="no-underline font-bold dim text-primary" | ||
:title="__('View')" | ||
> | ||
{{ __(':resource Details', { resource: display.text }) }} | ||
</router-link> | ||
</div> | ||
</div> | ||
</card> | ||
</loading-view> | ||
</modal> | ||
</template> | ||
<p v-else slot="value">—</p> | ||
</panel-item> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: ['resource', 'resourceName', 'resourceId', 'field'], | ||
data() { | ||
return { | ||
display: false, | ||
fields: [], | ||
} | ||
}, | ||
methods: { | ||
displayPivots(resource) { | ||
this.display = resource; | ||
this.loading = false; | ||
this.getPivotFields() | ||
}, | ||
/** | ||
* Get all of the available fields for an attachment. | ||
*/ | ||
async getPivotFields(resource) { | ||
await Nova.request() | ||
.get( | ||
`/nova-api/armincms/${this.resourceName}/pivot-fields/${this.field.resourceName}`, | ||
{ | ||
params: { | ||
resourceId: this.resourceId, | ||
relatedId: this.display.id, | ||
pivotId: this.display.pivotId, | ||
}, | ||
} | ||
) | ||
.then(({ data }) => { | ||
this.fields = data | ||
_.each(this.fields, field => { | ||
field.fill = () => '' | ||
}) | ||
}) | ||
}, | ||
/** | ||
* Resolve the component name. | ||
*/ | ||
resolveComponentName(field) { | ||
return field.prefixComponent | ||
? 'detail-' + field.component | ||
: field.component | ||
}, | ||
handleClose() { | ||
this.display = null | ||
this.$emit('close') | ||
}, | ||
}, | ||
computed: { | ||
}, | ||
} | ||
</script> |
Oops, something went wrong.