简体   繁体   中英

Edit Fields Not working; not updating, and sending empty array to backend

I am using Laravel version 9.41 and Nova 4. I can delete records, however it appears that on the frontend/JavaScript side of things my form fields are not having their contents captured and sent back to the server. My action_events table shows [ ] empty arrays as what is being sent.

I have spent a good four or five hours googling and checking that my Resources, field names etc. are all spelled correctly. I also see no error messages. Each time I get the green success message, "This has been updated." or whatever.

在此处输入图像描述

use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class Post extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var class-string<\App\Models\Post>
     */
    public static $model = \App\Models\Post::class;

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
        'text'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function fields(NovaRequest $request)
    {
        return [
            ID::make('id', 'id')->sortable(),
            Text::make('text', 'text')->sortable()
        ];
    }

Someone gave me the answer elsewhere: inn my Post model, after deleting/commenting out the lines in the screenshot below: all worked fine. There was no reason to define the following properties. They are not part of any Eloquent conversion. I did not need the following (in App/Models/Post):

在此处输入图像描述

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