Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
burasuk opened this issue Oct 18, 2024 · 3 comments
Open

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

burasuk opened this issue Oct 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@burasuk
Copy link

burasuk commented Oct 18, 2024

  • Laravel Version: 11.28.1
  • PHP Version: 8.3.4
  • Blueprint Version: 2.10.0
  • Platform: Windows

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
@burasuk burasuk added bug Something isn't working pending This issue is pending review labels Oct 18, 2024
@fftfaisal
Copy link

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

@burasuk
Copy link
Author

burasuk commented Oct 30, 2024

Thanks, i didn't notice that

@burasuk burasuk closed this as completed Oct 30, 2024
@jasonmccreary
Copy link
Collaborator

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.

@jasonmccreary jasonmccreary reopened this Oct 30, 2024
@jasonmccreary jasonmccreary removed the pending This issue is pending review label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants