Support the ongoing development of Laravel.io →
Packages Architecture

I'm creating a CMS system that we'll be using across a number of very different sites. Currently the system is composed of several packages for each of possible features of a new site - eg cms page, blog, shop product and some constant features shared between the other packages - images, downloads, etc.

The shared features like downloads are coded as a trait. For example the blog article model has the downloadfeature as a trait, the trait contains a standard eloquent relationship between the article and a download (with pivot table).

In the view for the blog article edit page there is a tab that displays the template for uploading a download.

This is all working fine, however as I create more I will want to be able to turn this on or off for different sites, I don't want to have to touch the package code as this will then cause issues on the other sites. I was hoping to be able to use the published config for (e.g.) the blog package to say if it should attach the downloads or images traits to them. On reflection I don't think this will be possible using traits.

I would also like to be able to only display the tabs I need in the admin area.

Can anyone explain how best I can organise the packages/models in a way that I can inject the different shared features into other packages using the config (or any other method that doesn't involve modifying actual package code.

Last updated 3 years ago.
0

Ive never fiddled with traits so I may be speaking out of stupidity but if I were wanting to re-use a code base across several sites id build an API that each 1 talks to and switch features on/off on their Laravel installation.

Or what about workbench packaging your code and including these common features through composer?

Last updated 3 years ago.
0

The reason I used a trait is because I want the relationships to work, so for example in the blog template I might want to get all the downloads using $article->downloads. If there's another way to do this without traits then I'm happy to do that. I don't quite understand how an API would help - perhaps you could expand on that?

All the features (blog/images/downloads/etc) are full packages, and I am including them with composer. This is why I don't want to touch the code within the packages on different sites except for the published configs.

Last updated 3 years ago.
0

Build API, Soap or Web Service.

Last updated 3 years ago.
0

Can you explain how an API would help?

I need something that I can pull this information (eg downloads attached to a blog article) out quickly and easily from a template. I'd like to be able to pull the blog article in the controller and send that to the template, the template could then use something like $article->downloads to retrieve all attached downloads.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

webal webal Joined 30 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.