I am trying to split my application out into seperate "modules".
I am not sure whether to leave the assets folder where it is and put everything in there for every module or how I would go about giving each module their own assets folder.
What is the best approach and what would I have to do in order to access the assets folders from each module?
Here is my directory structure so far:
Also am I right to put a Requests folder in each module?
Here is there relevant composer.json section:
"autoload": {
"classmap": [
"database",
"app/Modules"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
},
Take a look at the Packages section in the official Laravel documentation. It has sections on keeping things like translation files and other assets in your package, and publishing them when including your package in your applications.
Related
How to use git, when I have large tree of folders in file structure of web-project. Module, which I developing is separated by different folders in this file structure. As it is customary by MVC pattern concern.
In the overall file structure of web-project I have, roughly speaking:
model folder
controller folder
views folder
languages folder
and so on
I making changes in files at this folders and need track changes. These folders are not combined in one folder, that associated with module, that I developing. These folders are scattered in different parts of the file structure.
I could create git repository at the root of file structure and in .gitignore specify, which folders track. But I develop many modules. And I need separate git repositories for them.
Where and how create git repositories to developing many modules in large file structure?
If I init git repository at the root of web-project is it possible to create many repositories at the root of file structure for each module and for each repository specify which folders git should track?
I think simplest solution now days it's to keep your independent modules in separated repositories and then requesting them using composer.
I will show you some theoretical example of it.
I have project, which should use Payment Module. Payment Module is a separated repository with composer.json file provided in root directory.
For example:
{
"name": "company/payment-module",
"description": "Module handling payments from our customers.",
"autoload": {
"psr-4": {
"Company\\PaymentModule\\": "src/"
}
}
}
That gives you possibility of using any of modules created in any application/project you'll build.
So, for example in your project you can require Payment Module as dependency.
{
"name": "company/shop",
"type": "project",
"description": "The main repository of our shop.",
"autoload": {
"psr-4": {
"": "src/"
}
},
"repositories": [
{
"type": "git",
"url": "https://github.com/company/payment-module"
}
],
"require": {
"company/payment-module": "dev-master"
}
}
When you define modules you want in the project and install them using composer, they will be under vendor/ directory and will be autoloaded into the namespaces you define.
I am using Cake PHP 3, and under the src folder, I created a new folder called Helper and created a new file inside it. And now I went to composer.json and added the required file key inside the autoload. You can see it below:
"autoload": {
"psr-4": {
"App\\": "src"
},
"files": [
"./src/Helper/general_helper.php"
]
}
But after, doing composer dump-autoload, getting require(/opt/lampp/htdocs/project_name/vendor/composer/../../src/Helper/general_helper.php):
Its not under the vendor folder, I think that's why its giving the error. Any idea, how to solve this issue, cause I want to maintain a separate folder. Thanks.
I have a php application build on top of the Laravel framework. All my application specific modules are placed in their own Modules directory Modules\[Modulname].
These modules are autoloaded via PSR-4 in my composer.json:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
},
Is there a way to get an array or something containing all classes, traits and interfaces with all containing methods, attributes and PHPdoc-blocks from the Modules-directory ordered according to the namespace?
I want to build a documentation similar to the Laravel Api documentation.
i have edited psr-4 on composer.json
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Marka\\Urun\\": "vendor/Marka/Urun/src/",
"App\\": "app/"
},
"files": [
"vendor/Marka/Urun/src/helpers.php"
]
},
I want to change file(routes.php, helpers.php and Models,Views,Controllers) pathes to :
Vendor/Marka/Urun/
How can I do it ?
You're trying to get some modular structure if I get it right.
If so, instead of trying to set a different namespacing from composer for each of your modules under vendor directory; i think you may try to use something like http://sky.pingpong-labs.com/docs/2.0/modules
Otherwise as you may know, by using PSR-4 and directory structure, if you coded your files properly all necessary files would be loaded automatically as you named (namespaced) them.
By the way, just in case you didn't know you may also need a ServiceProvider to boot everything up for Laravel on your package.
I also suggest you to read https://laravel.com/docs/5.2/packages if you need any help about development structure/functionality.
I am attempting to create a sort of custom directory structure, my proposed structure is as follows
App/ - Contains all Laravel core code
Repo/ - Contains packages, each package contains Controllers, Views, Modals, Seeds and Migrations specific to that package
Is it possible via Composer or would it take a lot of core modification?
Controller routing in routes.php
Route::resource('account', '\Repo\Accounts\Accounts');
The first occurrence of accounts is the folder and the second being the class. I know I could write each directory seperetly then dump composer autoload, however when you have 30 seperate packages per app, it is a little time consuming. Am I missing something super straight forward?
This is possible with composer. Add inside of your composer.json:
"autoload": {
"classmap": [
// ...
],
"psr-4": {
"Repo\\" : "Repo"
}
},
Then you can use classes inside of the /Repo directory, and classes in there will reside in the \Repo namespace.