简体   繁体   中英

Laravel Nova Morphing issue

The original developer of this Laravel App left and now I have been handed over the task. The admin is created in Nova which I have zero clue of. We have a User.php resource that can have and image as it's Avatar. The developer is using a pivot table images and has used "MorphOne::make('image')," but it was giving error "HasOne relationship has already filled" yet there are no images relation in DB in images table.

When I change MorphOne to MorphMany, it saves the image but it allows many images to upload too. I'm new to this an rarely have found helpful resource to tackle this. Let me know what I missed to track this issue.

User.php

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Text::make('Name')
            ->sortable()
            ->rules('required', 'max:255'),
        Text::make('Email')
            ->sortable()
            ->rules('required', 'email', 'max:254')
            ->creationRules('unique:users,email')
            ->updateRules('unique:users,email,{{resourceId}}'),
        Password::make('Password')
            ->onlyOnForms()
            ->creationRules('required', 'string', 'min:8')
            ->updateRules('nullable', 'string', 'min:8'),
        Boolean::make('Verified By Email'),
        DateTime::make('Created At')->format('LLLL')->hideFromIndex(),

        BelongsToMany::make('Roles'),
        BelongsToMany::make('Permissions'),

        MorphOne::make('image'),
        MorphOne::make('Location'),
        HasMany::make('LogActivity','logs')

    ];
}

Image.php

public function fields(Request $request)
{
    $fields = [
        ID::make()->sortable(),
        \Laravel\Nova\Fields\Image::make('Src')
            ->rules('required')
            ->disk('images')
            ->prunable(),

        MorphTo::make('Image')->types([
            Song::class,
            Post::class,
            User::class,
            Event::class,
            Competition::class,
        ])


    ];


    return $fields;
}

当 Laravel(非 Nova 基础应用程序)模型上的关系设置为 morphMany 并将该关系更改为 morphOne 并修复它时,我收到此错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM