orchidsoftware / crud

Simplify the process of building CRUD (Create, Read, Update, Delete) functionality in Laravel using the features of Orchid.
https://orchid.software
MIT License
137 stars 34 forks source link

Call to a member function can() on null #96

Closed m-pastuszek closed 2 months ago

m-pastuszek commented 7 months ago

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

ksardv commented 7 months ago

@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.

m-pastuszek commented 7 months ago

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

tabuna commented 5 months ago

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

m-pastuszek commented 2 months ago

Hello @tabuna, I can confirm that it works without issue after update.