Skip to content

Batch Action with form is not working #199

@b72

Description

@b72

Describe the bug
I created a batch action with form input. When I submit the form I am getting this error
OpenAdmin\Admin\Form::model(): Return value must be of type Illuminate\Database\Eloquent\Model, OpenAdmin\Admin\Actions\Interactor\Form returned {"userId":1,"exception":"[object] (TypeError(code: 0): OpenAdmin\\Admin\\Form::model(): Return value must be of type Illuminate\\Database\\Eloquent\\Model, OpenAdmin\\Admin\\Actions\\Interactor\\Form returned at /var/www/html/vendor/open-admin-org/open-admin/src/Form.php:188)

To Reproduce
Here is my Batch Action

<?php

namespace App\Admin\Actions\PO;

use App\Models\PO\PurchasedItems;
use OpenAdmin\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class SetWareHouse extends BatchAction
{
    protected $selector = '.report-pages';

    public function handle(Collection $collection, Request $request)
    {
        foreach ($collection as $model) {
            if ($model instanceof PurchasedItems) {
                $model->storage_location = $request->input("storage_location");
                $model->save();
            }
        }

        return $this->response()->success('Report submitted!')->refresh();
    }

    public function form()
    {
        $this->text('storage_location', 'storage_location')->rules('required');
    }

    public function html()
    {
        return "<a class='report-pages btn btn-sm btn-danger show-on-rows-selected d-none me-1'><i class='icon-info-circle'></i>Set Store</a>";
    }
}

System

  • Open-admin version : 1.0.27
  • PHP version : 8.3
  • Laravel Version: 11.36.1
  • OS: Linux
  • Browser chrome
    Screenshot 2024-12-21 033926

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions