open-admin icon indicating copy to clipboard operation
open-admin copied to clipboard

Batch Action with form is not working

Open b72 opened this issue 1 year ago • 2 comments

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

b72 avatar Dec 20 '24 21:12 b72

is anyone this issue fixed? I'm also still faced with this issue

sanjayaharshana avatar Feb 26 '25 03:02 sanjayaharshana

Did you try the develop branche, because I think my pull request is in there https://github.com/open-admin-org/open-admin/commit/b1b363189f13e0cd5c850a6183c963503b8e24a1

bytebrain avatar Feb 26 '25 18:02 bytebrain