crud icon indicating copy to clipboard operation
crud copied to clipboard

Call to a member function can() on null

Open m-pastuszek opened this issue 7 months ago • 3 comments

I have custom action for bulk deleting records.

public function handle(Collection $models)
    {
        $models->each(function (Model $model) {
            $model->delete();
            event(new MyEvent$model));
        });

        Toast::message('Custom message');
    }

Action seems to be completed, because selected rows are being deleted, but after that I get error Call to a member function can() on null. It's caused by line 80 in orchid\crud\src\CrudScreen.php:

 protected function can(string $abilities, Model $model = null): bool
    {
        return $this->request->can($abilities, $model);
    }

Am I doing something wrong? I use custom authentication with Fortify and LDAP, but I don't think it's related to that.

Error share on Flare: https://flareapp.io/share/yPa9EnYP

m-pastuszek avatar Jan 23 '24 13:01 m-pastuszek

@m-pastuszek I ran into the same issue. Since my admin panel is only for one admin user and not for regular users and thus the permissions are not a problem for me I just set in CrudScreen line 80 return true. It does the job for me, but I highly do not recommend doing so since it will always allow you to do the action. The issue is not present in Laravel 9 and the corresponding orchid versions, but I am running Laravel 10 so downgrading is not an option. I will check into the issue when I have some more time to investigate.

ksardv avatar Jan 26 '24 16:01 ksardv

Okay, thank you for information. So it's related to custom authentication?

m-pastuszek avatar Jan 30 '24 14:01 m-pastuszek

It should be fixed with the release of https://github.com/orchidsoftware/crud/releases/tag/4.2.0, please update.

tabuna avatar Apr 20 '24 02:04 tabuna