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

Ignoreable routes #843

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open

Conversation

Justin-vdm
Copy link

@Justin-vdm Justin-vdm commented Sep 5, 2024

In my implementation, I only require the use of OData with GET requests. However, Lodata registers a Route::any by default, which intercepts all HTTP methods.
This causes conflicts when trying to define standard routes for other methods (e.g., POST, PUT, DELETE) since they are routed to Lodata due to the shared prefix between the API and Lodata routes.

To resolve this, I've introduced a getter and setter in the model that determines whether a route should be registered.
This property defaults to true, providing flexibility in controlling which routes are handled by Lodata and enabling the ability to override the base route.

Example Usage:

In AppServiceProvider:
Add the following line inside the boot() method to stop Lodata from automatically registering routes:

Lodata::ignoreRoutes();

In api.php:
Define a specific GET route for OData requests:

Route::get('{path}', [OData::class, 'handle'])->where('path', '(.*)');

@Justin-vdm Justin-vdm changed the title Ignorable routes Ignoreable routes Sep 5, 2024
@27pchrisl
Copy link
Contributor

Hi @Justin-vdm, if you need this level of control I think you might be better off opting out of lodata’s discovery (https://laravel.com/docs/11.x/packages#opting-out-of-package-discovery) and implementing only the pieces of the service provider you need?

@Justin-vdm
Copy link
Author

Hi @27pchrisl, I use all the functionality except for Route::any(). Is there a more efficient approach to avoid using it while maintaining control over the routes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants