How to change the Modules "Modules" folder name? - laravel

I am using Laravel Modules
https://github.com/nWidart/laravel-modules
This is the Folder Structure with Modules.
Is there any way to change it? Like I want to create
Admin\Category
Means my Modules folder name will be Admin
"autoload": {
"psr-4": {
"App\": "app/",
"Modules\": "Admin/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
I tried with this but not working!
Thanks

Based on documentation of package yes you can.
First step run this command
php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Second Step in Config/laravel-modules.php will find ["Modules path","Modules assets path","Default Namespace"] you can customize them
Last Step in composer.json
"autoload": {
"psr-4": {
"App\": "app/",
"Admin\": "Admin/",
"Database\Factories\": "database/factories/",
"Database\Seeders\": "database/seeders/"
}
},
then run composer dump-autoload

Related

Trying to override the method of laravel passport package by the help autoload psr-4 but does not get expected result

Composer.json
"autoload": {
"exclude-from-classmap": [
"vendor\\laravel\\passport\\src\\Http\\Controllers\\AccessTokenController.php"
],
"psr-4": {
"App\\": "app/",
"Laravel\\Passport\\": "app/Override/" //tried "Passport//" only also
}
},
I have file AccessTokenController.php which lie in vendor\laravel\passport\src\Http\Controllers\ and i create Override folder inside App directory on where i copied that file and make changes in code
And finally when i do :
composer dump-autoload
i get error as :Class Laravel\Passport\Http\Controllers\AccessTokenController located in ./app/Override/AccessTokenController.php does not comply with psr-4 autoloading standard. Skipping.
seems problem with namespace which i couldn't figure out though trying some of the ways ..
Anyone can help me ?
I would simply override the route from within the app as mentioned here. No need for the approach you mentioned above.
However, if you want to keep going this route you can try the following.
"psr-4": {
"App\\": "app/",
}
"exclude-from-classmap": [
"Laravel\\Passport\\Http\\Controllers\\AccessTokenController"
],
"files": [
"app/Override/AccessTokenController.php"
],
I solved it by including complete namespace of AccessTokenController.php.so final code would look like this:
"autoload": {
"exclude-from-classmap": [
"vendor\\laravel\\passport\\src\\Http\\Controllers\\AccessTokenController.php"
],
"psr-4": {
"App\\": "app/",
"Laravel\\Passport\\Http\\Controllers\\":"app/Override/"
}
}

Autoloading of classes of a local TYPO3 extension

In my following composer.json I am requiring extensions, which are in the same Git repository as the whole project. So I add in the repositories section and later I do composer req vendor/site_package:#dev in order to require my local extension.
Now I realized, that some classes of the extension are not autoloaded.
Do I need to additional add the autoload part as shown below in the composer.json of the project?
{
"name": "site-package",
"description": "Base composer.json",
"repositories": [
{
"type": "path",
"url": "./packages/*"
}
],
"require": {
"typo3/cms-backend": "^10.4",
"typo3/cms-belog": "^10.4",
"typo3/cms-beuser": "^10.4",
"typo3/cms-core": "^10.4",
...
"vendor/site_package": "#dev",
"georgringer/news": "^8",
...
},
"autoload": {
"classmap": [
"public/typo3conf/ext/site_package/Classes"
],
"psr-4": {
"Vendor\\SitePackage\\": "public/typo3conf/ext/site_package/Classes"
}
},
"extra": {
"typo3/cms": {
"root-dir": "public",
"web-dir": "public"
}
},
"config": {
"vendor-dir": "vendor",
"bin-dir": "bin"
},
"scripts": {
"typo3-cms-scripts": [
"typo3cms install:generatepackagestates",
"typo3cms install:fixfolderstructure"
],
"post-autoload-dump": [
"#typo3-cms-scripts"
]
}
}
In ext:site_package I have the following autoload section as well:
"autoload": {
"psr-4": {
"Vendor\\SitePackage\\": "Classes",
}
},
Do I need both? Why?
You should never mix those 2 composer.json.
As you already follow the approach of having a directory packages (which is a good thing) each extension inside there needs an own composer.json file which of course also needs a section
"psr-4": {
"Vendor\\MyExt\\": "Classes"
}
By requiring this package, this autoload information will be used.
If you would still have the custom extension inside typo3conf/ext/my_ext, that composer.jsonfile would not be taken into account and you need something like
"psr-4": {
"Vendor\\MyExt\\": "typo3conf/ext/myext/Classes"
}
The autoload part is only needed in your site package composer.json. It's not necessary to put it also in the composer.json in your root folder.
Please refer to the documentation how the composer.json of your site package should look like.
If you still have problems with autoloading, try composer dump-autoload or remove the extension and require it again. And make sure to check the upper-/lowercase of your namespace. It's case sensitive. If you change that after you required the site package, you need to remove and require the package again.

How to create a Module in Root Directory in Laravel

I want to work with Laravel-Modules
I can create Modules under Module Folder. But I want to create a Module in the Root directory and while it will run, the Root Module will run first.
Is it possible?
If possible then give me the way.
I have tried with
"psr-4": {
"App\\": "app/",
"Modules\\": "/"
}
But it is giving me an Error:
Directory name must not be empty.
Try This:
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}

Composer not installing local package dependencies

In my Laravel 5.4 composer.json file I have the following that autoloads my custom package. Note, that this package is not published and is being loaded locally.
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Module\\": "packages/vendor/module/src"
}
},
And then in my package composer.json file I have the following
{
"name": "vendor/module",
"description": "A custom package",
"version": "1.0.0",
"type": "project",
"authors": [
],
"minimum-stability": "dev",
"require": {
"laravelcollective/html": "^5.4.0"
}
}
However, when I run composer install from the root Laravel directory, it never picks up the laravelcollective/html package that I am requiring.
Is there a way to load in dependencies on a local package that is not published?
I believe I found a solution, all though it may not be the best method for local package development it is working for me.
In the root composer.json file, I added the following and running a composer update from the root of the application seems to now pick up the package and it's dependencies and installs everything into the main vendor directory of the root application.
"repositories": [
{
"type": "path",
"url": "packages/vendor/module"
}
],
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7",
"vendor/module": "1.0.*"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Module\\": "packages/vendor/module/src"
}
},
The good thing about this method is it creates a symbolic link only for the custom package, thus you can continue to write updates in the packages directory and the changes will take affect instead of having to commit to your local git repository if you set the type to vcs in the repositories field of the composer.json.
I also had to specify in the require-dev field the version number so that it passes the version constraint, otherwise you would get a warning that the package does not meet the minimum version requirements when running composer.

composer psr-4 autoload with same key

i have this setup into composer.json
"autoload": {
"psr-4": {
"": "src/",
"App\\": "src/App"
}
}
with this folder structure:
src
---App
------MyClass.php --> namespace \App;
---Somedir
------Otherdir
---------OtherClass.php --> no namespace
File under src/App folder will be loaded, file under Somedir not.
There is something wrong?
You can use combinations of autoloaders, so adjust your composer.json to use both a PSR-4 autoloader for classes with namespace, and use classmap autoloader for those that do not have namespace:
{
"autoload": {
"classmap": [
"src/SomeDir"
],
"psr-4": {
"App\\": "src/App"
}
}
}
For reference, see https://getcomposer.org/doc/04-schema.md#autoload.
The disadvantage of using a classmap autoloader is that if you add or remove classes in the directories which are loaded via classmap autoloader, the classmap needs to be regenerated:
$ composer dump-autoload

Resources