laravel-shift / blueprint

A code generation tool for Laravel developers.
MIT License
2.9k stars 276 forks source link

undefined method 'authorize' when generate controller with policy #701

Open burasuk opened 1 month ago

burasuk commented 1 month ago

Issue:

Blueprint generate code that not exists in Laravel 11.

public function index(Request $request)
    {
        $this->authorize('index', Customer::class);// <= here
        $customers = Customer::all();
        return new CustomerCollection($customers);
    }

draft.yaml:

controllers:
  Customer:
    resource: api.index, api.store, api.show,api.update,api.destroy     
    meta:
      policies: index,store,show,update,destroy
fftfaisal commented 3 weeks ago

laravel 11 remove all trait from base controller thats why it thow an error. You can use the AuthorizeRequest trait in the controller.

burasuk commented 3 weeks ago

Thanks, i didn't notice that

jasonmccreary commented 3 weeks ago

While I agree with @fftfaisal as a potential workaround, this should probably be fixed to use the facade. There are some open issues for other Laravel 11 optimizations. So I'm going to reopen this.