dcasia / nova-inline-morph-to Goto Github PK
View Code? Open in Web Editor NEWA Laravel Nova field for displaying morphTo relationship inline.
License: MIT License
A Laravel Nova field for displaying morphTo relationship inline.
License: MIT License
doesnt work on nova 4/laravel 10
Is this package support nova4?
Hello, it seems like computed fields are not supported by this package.
For example I have this in my embedded resource:
Text::make('Name', function () {
return $this->first_name.' '.$this->last_name;
});
First name and last name properties are always null. I searched in the code and there is a new model created (instead of using an existing model) here https://github.com/dcasia/nova-inline-morph-to/blob/master/src/InlineMorphTo.php#L68 which might explain that behaviour but I'm not sure if that's the issue. Do you have an idea?
First off, thank you for all your work on this package. It's looking likely to play a central roll in the content management feature of a few projects.
I did run into a situation when an InlineMorphTo field includes a Resource that uses a field provided by Advanced Nova Media Library. It would appear that the situation could occur with any packaged field that returns anything but null
from fillAttributeFromRequest
.
To solve, I modified lines 253โ257 of src/InlineMorphTo.php
to
foreach ($fields as $field) {
$fill_value = $field->fill($request, $relatedInstance);
if (is_callable($fill_value)) {
call_user_func($fill_value);
}
}
This at least solves for situations where fillAttributeFromRequest
returns a callback. I'm not sure if there are other possible scenarios that are missed since fillAttributeFromRequest
can return mixed
If the above seems like a reasonable fix, I'm happy to provide a pull request.
Thanks!
related to #16
in the recent Nova and Laravel environment updating 2nd level relations no longer work (but it is possible to change them in the frontend).
Would be great if you can have a look. I think the best solution would be to allow the developer to decide if updating a relation-ship is possible or not.
this is a specific case, I'm using this package combined with :
https://novapackages.com/packages/kirschbaum-development/nova-inline-relationship
so I can create inline sub content that has Morph capacity...
in that case , when I add a new content (inline) the dropdown stays disabled
:
note : nova-inline-morph-to
works OK when used directly on my sub model.
When adding inline morph to User, all resources can be created as intended (eg Teachers/Admins) except for Students.
InlineMorphTo::make('Userable')
->types( [
Individual::class,
Student::class,
Teacher::class,
SchoolAdmin::class,
Admin::class,
])
->default(Student::class)->hideFromIndex()->hideFromDetail(),
Hello,
Before anything else, thank you for this package.
I am trying to use InlineMorphTo which one of given types of Nova Resource contains a BelongsTo relationship.
For instance, consider the Article Resource example in README:
InlineMorphTo::make('Template')
->types([
\App\Nova\Video::class,
\App\Nova\Image::class,
\App\Nova\Text::class,
\App\Nova\Gallery::class,
]),
If the Gallery resource contains a BelongsTo field that points to an User resource, I get the following error when accessing pages related to the Article resource:
Call to undefined method \App\Nova\Gallery::user()
The demo GIF shows the template drop-down with descriptive options in mixed case. What do I need to set to override those so they are not just the pluralized resource (model?) name?
I've tried setting label, title, and name properties on the morphed models and nova resources with no luck.
Thanks for a great and useful add-on functionality for Nova !
Hey,
I noticed that the resourceId property of nova fields which are morphed is undefined.
I have some components, which rely on the property and they break inside the morph due to the missing property. But its also missing on any default nova components like the textarea, if you inspect them via the vue dev tools.
Is there any way how to pass it through from the MorphTo (this has the property set) down to its children?
Greetings,
maybe something you can incorporate into the package.
Following a working solution to automatically list morphables from a given directory Nova/Metricables
where the Nova Resources for the morphables are defined:
Helper function:
//https://stackoverflow.com/questions/31837075/laravel-get-list-of-models
function getClassesList($dir)
{
$classes = \File::allFiles($dir);
foreach ($classes as $class) {
$class->classname = str_replace(
[app_path(), '/', '.php'],
['App', '\\', ''],
$class->getRealPath()
);
}
return $classes;
}
then in resource:
$classlist = getClassesList(app_path('Nova/Metricables'));
$metricables = [];
foreach ($classlist as $c) {
$metricables[] = $c->classname;
}
and the field definition
InlineMorphTo::make('Metricable')->types($metricables)
maybe you can shortcut it into
InlineMorphTo::make('Metricable')->typesFromDir(app_path('Nova/Metricables'))
Hello.
I'm facing a new issue, described as follows:
Imagine that there's another relationship field in the Article resource:
MorphMany::make('Collection')
The details page, when resource uses the HasInlineMorphToFields trait, is completely replaced by one that does not show this new relationship field.
Another issue I've found is that labels are not used to display the morph types. (singularLabel and pluralLabel). Instead, I'm seeing the actual Resource class.
See the following screens, before and after using this package.
Thanks again for this great package.
Am struggling with the following situation for some hours... the GUI works, when saving I get following exception
"message": "Trying to access array offset on value of type null",
"exception": "ErrorException",
"file": "/vendor/digital-creative/nova-inline-morph-to/src/InlineMorphTo.php",
"line": 285,
Debugging shows that
$this->meta[ 'resources' ]->where('className', $resourceClass)->first()
returns null (but $resourceClass is valid).
Any idea what the issue might be?
Method DigitalCreative\InlineMorphTo\InlineMorphTo::typeUpdateable does not exist
Please merge #25
would be great to set a default model with the common nova syntax:
InlineMorphTo::make('Metricable')
->types($metricables)
->withMeta([
'value' => $this->metricable_type ?? \Metricables\Standard::class
]),
Just released https://github.com/Nova-BI/nova-databoards which makes heavy use of your great packages.
I understand the morphable type is read-only in edit mode on purpose to secure a valid data structure. However when having a morphable which has a morphable the 2nd level morphable type is not read-only. Is this a valid behaviour?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.