- Does this package work with Laravel 10 or 11?
- No, this package is abandoned and only officially supports Laravel 5.8–8.x. Laravel 10+ introduces breaking changes (e.g., route caching, improved resource classes) that may cause conflicts. You’d need to fork or patch it manually for compatibility.
- How do I add links to a JsonResource for a custom controller?
- Use the `HasLinks` trait in your resource class and call `links(YourController::class)` in the `toArray` method. The package auto-generates URLs for standard REST actions (e.g., show, edit, delete) based on your controller’s routes. For non-standard routes, you may need to override the `links` method.
- Can I filter links based on user permissions (e.g., hide delete for non-admins)?
- The package doesn’t include built-in permission filtering, but you can manually filter links in the `toArray` method or use middleware to conditionally include/exclude actions. For example, check `auth()->user()->can('delete')` before returning the `delete` link.
- Will this work with API versioning (e.g., /api/v1/users)?
- No, the package doesn’t natively support API versioning. If your routes are namespaced (e.g., `Route::prefix('api/v1')->group(...)`), you’ll need to manually ensure the generated links include the correct version prefix or override the route resolution logic.
- How do I test link generation in my CI pipeline?
- Mock the route generation by using Laravel’s `Route::getRoutes()` to verify links. For example, assert that `links(UserController::class)` returns the expected URLs by comparing against hardcoded route patterns. Test edge cases like optional parameters or custom route names.
- Are there alternatives to this package with active maintenance?
- Yes, consider `spatie/laravel-hal` for HATEOAS support with HAL+JSON format, or `nWidart/laravel-routes` for dynamic route generation. For modern Laravel, you might also build custom link logic using Laravel’s `route()` helper or a service class to avoid dependency risks.
- What happens if I use route caching in Laravel (e.g., `php artisan route:cache`)?
- Route caching may cause stale links if routes are updated without clearing the cache. The package doesn’t auto-detect cache changes, so you’ll need to manually refresh the cache (`php artisan route:clear`) after route modifications or implement a fallback to uncached route resolution.
- Can I use this package with Laravel Sanctum or Passport for API auth?
- Yes, but you must manually filter links to avoid exposing unauthorized routes. For example, exclude the `delete` link if the user lacks permissions. Use middleware or resource methods to gate access before generating links.
- How do I handle nested resources (e.g., `users/{user}/posts`)?
- The package doesn’t natively support nested resource links. You’ll need to manually construct URLs for nested routes or extend the `links` method to handle dynamic parameters. For example, pass the parent resource ID to the controller action.
- What’s the migration path if this package is deprecated or breaks?
- Replace the `HasLinks` trait with manual URL generation using Laravel’s `route()` helper or a custom service. For example, replace `links(UserController::class)` with `['show' => route('users.show', $this->id)]`. Audit all JsonResource classes to ensure no hard dependencies remain.