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.
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?
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community