GithubHelp home page GithubHelp logo

dcasia / nova-inline-morph-to Goto Github PK

View Code? Open in Web Editor NEW
33.0 2.0 13.0 4.8 MB

A Laravel Nova field for displaying morphTo relationship inline.

License: MIT License

JavaScript 4.62% Vue 31.93% PHP 63.45%
nova laravel polymorphic morph inline laravel-nova-field

nova-inline-morph-to's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nova-inline-morph-to's Issues

Nova4

Is this package support nova4?

Support for computed fields

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?

Filling a relationship field fails if `fillAttributeFromRequest` returns a callback

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!

2nd level polymorphic relationships no longer update

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.

Call to undefined method Laravel\Nova\ResourceToolElement::fill()

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(),

Image of Error

Unable to use relationship on embedded models

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()

How do you override the names of the morphTo resources?

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 !

resourceId is undefined

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,

get morphables from directory

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'))

HasInlineMorphToFields trait prevents other relationships fields to be displayed

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.
Screenshot 2019-10-03 at 21 26 29

Screenshot 2019-10-03 at 21 26 51

Trying to access array offset on value of type null

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?

Allow to set default

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
]),

Read only morphable type?

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?

Laravel 2020-07-01 11-21-42

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.