Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

isaackearl's avatar

Need an opinion: Include Laravel package in my package or make my own implementation?

Hello!

Need some opinions! I'm creating an API package similar to something like Dingo/api except for a bit lighter.

I've created many APIs etc the past couple of years and I've developed my own set of tools for it, and I thought I would make it available so I'm rewriting some of it as a proper package now.

One portion of it uses laravel-fractal the great package here from spatie: https://github.com/spatie/laravel-fractal

I'm wondering if I should include that as a dependency in my package and register the service provider for it in my own service provider etc? Or should I make my package more generic and implement my own Fractal provider/service ?

I really like laravel-fractal and the extra goodies it already provides, but I want registering my service provider to be easy as possible, and I also like the idea of people being able to use whatever phpleague/fractal package they want (for example for a project that already uses fractal and is adding my package on top of it).

Might be a silly question but I appreciate any feedback and which route I should take. Thanks!

0 likes
3 replies
isaackearl's avatar

Sorry to bump my own question, any idea on best practice with this situation?

ryantbrown's avatar

If it's required for your package to run then you need to include it as a dependency or it will break. Composer will warn the user if there are versioning errors, its not your responsibility.

Regarding the service provider bit, I don't think it matters as long as you document it. If part of the setup for using your package is to register 2 service providers it's no big deal.

I would personally register it in the package, it's required for the app to run and nothing is going to happen if the user also registers it. Just make sure to document it.

isaackearl's avatar

thanks @ryantbrown for the response. I think I am leaning towards including the package in my package. It's not really required as I could implement the things it does myself, however the laravel-fractal package is really nice and has a nice api/syntax etc for using Fractal. I think in the end it makes sense for me to include it since I am essentially building the package the way I would like to use it. If others want to use it that would just be a bonus.

Please or to participate in this conversation.