Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

Last update: Jun 30, 2022

Packagit

Packagit is amazing laravel modules management, you could manage huge project with many separate laravel modules.

You could run packagit or a short name p, such as p new Auth, a module named Auth would be created.

You can make artisan command running anywhere, All the packagit commands are same with artisan like following table.

artisan packagit
php artisan tinker p tinker
php artisan make:controller p make:controller
php artisan make:migration p make:migration
php artisan make:job p make:job
php artisan test p test
php artisan ... p ...

for example, you have a project named starter, directories layout:

starter
    └── modules
        ├── Auth
        ├── Components
        └── Wechat

change path to starter/modules/Auth, and run p make:controller:

cd starter/modules/Auth
p make:controller DemoController

DemoController.php would be created for Auth module.

modules/Auth/src/Http/
└── Controllers
   └── DemoController.php

change path to starter/app/Http/Controllers, and p make:controller:

cd starter/app/Http/Controllers
p make:controller DemoController

DemoController.php would be created for starter, because of current path doesn't include any module.

So when you run p make:xxx laravel command, packagit would scan the path, if current is in a module path, it will create for the module, otherwise for the project.

Installation

composer global require packagit/packagit

You MUST install packagit with global, and add composer bin to the $PATH environment.

Following command would help you find the global bin path:

composer global config bin-dir --absolute --global

# such as $HOME/.composer/vendor/bin, add to $PATH
# save to ~/.zshrc or ~/.bashrc
export PATH=$HOME/.composer/vendor/bin:$PATH

Usage

1. Custom package namespace (Optional)

run p custom

config/packagit.php file would be created, you could customize namespace by edit this file, skip here if you don't need custom.

2. Create a new module

run packagit new ModuleName

you also could group many modules as Components or others you want.

packagit new Components/NetUtil
packagit new Components/Updater
packagit new Components/Downloader

A Module Structure:

├── README.md
├── composer.json
├── config
│   └── config.php
├── database
│   ├── factories
│   ├── migrations
│   └── seeders
│       └── DatabaseSeeder.php
├── package.json
├── resources
├── routes
│   ├── api.php
│   └── web.php
├── src
│   ├── Models
│   └── Providers
│       ├── CommandServiceProvider.php
│       ├── RouteServiceProvider.php
│       └── ServiceProvider.php
├── tests
│   ├── Feature
│   └── Unit
└── webpack.mix.js

Load modules in project

1、composer require wikimedia/composer-merge-plugin

edit project/composer.json => extra => merge-plugins:

    "extra": {
        "merge-plugin": {
            "include": [
                "modules/*/composer.json",
                "modules/Components/*/composer.json"
            ],
            "recurse": false,
            "replace": true,
            "ignore-duplicates": false,
            "merge-dev": true,
            "merge-extra": true,
            "merge-extra-deep": true
        },
        "laravel": {
            "dont-discover": []
        }
    },

2、composer dump-autoload

3、edit project/config/app.php

    'providers' => [
        \Packagit\[MoudleName]\Providers\ServiceProvider::class, 
    ],

All done, modules should work well.

License

The Apache License 2. Please see License File for more information.

GitHub

https://github.com/packagit/packagit
Comments
  • 1. 服务提供者是否可以自动加载呢?

    开发完成了项目后,一般期望能使用 composer.jsonextra 配置,完成服务提供者的自动加载,并且期望能通过事件、数据的的方式完成插件的各方面管理。不希望改动到文件 app/config.php 与主项目的各项文件内容。

    这里之前的参考资料:

    注册模块的命名空间:https://gitee.com/fresns/plugin-manager/blob/master/src/Providers/PluginServiceProvider.php#L35-38

    注册每一个插件的命名空间、别名:https://gitee.com/fresns/plugin-manager/blob/master/src/Support/Plugin.php#L118-120

    Reviewed by mouyong at 2022-06-16 17:19
  • 2. 运行数据填充和模型工厂的时候报错..

    image
    p db:seed --class=ArticleSeeder
    Work Module: /modules/ArticleApi
    
       Error 
    
      Class "Database\Factories\App\Models\ArticleFactory" not found
    
      at /Users/chensuilong/Desktop/phpproject/laravel9xx/laravel9/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:770
        766▕     public static function factoryForModel(string $modelName)
        767▕     {
        768▕         $factory = static::resolveFactoryName($modelName);
        769▕ 
      ➜ 770▕         return $factory::new();
        771▕     }
        772▕ 
        773▕     /**
        774▕      * Specify the callback that should be invoked to guess factory names based on dynamic relationship names.
    
          +1 vendor frames 
      2   /Users/chensuilong/Desktop/phpproject/laravel9xx/laravel9/database/seeders/ArticleSeeder.php:28
          App\Models\Article::factory()
    
    

    参考教程 https://learnku.com/docs/laravel/9.x/database-testing/12261#defining-model-factories

    正常目录下摆放是可以运行成功的.... 用您的包以后似乎路径有些错误 无法运行数据填充~~

    望大佬测试一下 谢谢

    laravel9/modules/ArticleApi/database/factories/ArticleFactory.php

    <?php
    
    namespace ll\ArticleApi\Database\Factories;
    
    use Illuminate\Database\Eloquent\Factories\Factory;
    use ll\ArticleApi\Models\Article;
    
    class ArticleFactory extends Factory
    {
        protected $model = Article::class;
        public function definition()
        {
            return [
                'title' => $this->faker->title(),
                'content' => $this->faker->text(),
                'show' => 1,
            ];
        }
    }
    
    

    laravel9/modules/ArticleApi/database/seeders/ArticleSeeder.php

    <?php
    
    namespace ll\ArticleApi\Database\Seeders;
    
    use Illuminate\Database\Seeder;
    use ll\ArticleApi\Models\Article;
    use ll\ArticleApi\Models\Tag;
    
    class ArticleSeeder extends Seeder
    {
        /**
         * Run the database seeds.
         *
         * @return void
         */
        public function run()
        {
    
            Article::factory()
                ->count(10)
                ->has(Tag::factory()->count(3))
                ->create();
        }
    }
    
    

    laravel9/modules/ArticleApi/src/Models/Article.php

    <?php
    
    namespace ll\ArticleApi\Models;
    
    use Dcat\Admin\Traits\HasDateTimeFormatter;
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\SoftDeletes;
    use Illuminate\Database\Eloquent\Model;
    
    class Article extends Model
    {
        use HasFactory;
        use HasDateTimeFormatter;
        use SoftDeletes;
        protected $fillable = [
            'title', 'content', 'show',
        ];
        public function tags()
        {
            return $this->belongsToMany(Tag::class)->withTimestamps();
        }
    
    }
    
    
    

    laravel9/modules/ArticleApi/src/Models/Tag.php

    <?php
    
    namespace ll\ArticleApi\Models;
    
    
    use Dcat\Admin\Traits\HasDateTimeFormatter;
    
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;
    
    class Tag extends Model
    {
        use HasFactory;
        use HasDateTimeFormatter;
        protected $fillable = ['name'];
    
        public function articles()
        {
            return $this->belongsToMany(Article::class);
        }
    }
    
    

    数据库迁移文件

    <?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class CreateArticle extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            if (Schema::hasTable('articles')) {
                return true;
            }
            Schema::create('articles', function (Blueprint $table) {
                $table->id()->unsigned()->index();
    
    //            $table->foreignId ('user_id');
    
                $table->string('title', 200)->default('')->comment('文章标题');
    //            $table->string ('cover_url')->default ('')->comment ('文章封面图片');
    //            $table->string ('desc', 200)->default ('')->comment ('文章摘要');
                $table->string('tags', 255)->default('')->comment('文章标签');
                $table->mediumText('content')->comment('内容');
                $table->tinyInteger('show')->default(0)->comment('是否显示');
                $table->timestamps();
                $table->softDeletes();
            });
    
            Schema::create('tags', function (Blueprint $table) {
                $table->id()->unsigned()->index();
                $table->string('name');
                $table->timestamps();
            });
            Schema::create('article_tag', function (Blueprint $table) {
                $table->bigInteger('article_id')->unsigned()->index();
                $table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
    
                $table->bigInteger('tag_id')->unsigned()->index();
                $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
    
                $table->timestamps();
    
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('article_tag');
            Schema::dropIfExists('articles');
            Schema::dropIfExists('tags');
        }
    }
    
    
    
    Reviewed by duolabmeng6 at 2022-06-05 08:34
  • 3. laravel9 bug

    p custom                       
    
       Error 
    
      Class "Laravel\Package\Exceptions\FileAlreadyExistException" not found
    
      at /Users/chensuilong/.composer/vendor/packagit/packagit/src/Commands/CustomCommand.php:43
         39▕      */
         40▕     public function handle()
         41▕     {
         42▕         $to = config_path('packagit.php');
      ➜  43▕         throw_if(file_exists($to), new FileAlreadyExistException('config/packagit.php is already existing'));
         44▕ 
         45▕         $from = dirname(__DIR__, 2) . '/config/config.php';
         46▕         copy($from, $to);
         47▕         $this->line('Config file copied to  ['.$to.']');
    (base) 
    
    
    Reviewed by duolabmeng6 at 2022-06-05 02:03
  • 4. 执行流程应该调整下吧

    1. p custom 生成自定义配置文件
    2. p new 生成模块

    同时 custom 的时候,应该就可以安装 wikimedia/composer-merge-plugin 同时配置 composer ; app.php 的 providers 在模块中,已经声明了,这里应该不需要再配置了吧。

    @zencodex

    Reviewed by myxiaoao at 2022-06-04 08:57
  • 5. laravel 9 p db:seed 执行失败~~

    image
     p db:seed
    Work Module: /modules/ArticleApi
    
       Illuminate\Contracts\Container\BindingResolutionException 
    
      Target class [Packagit\ArticleApi\Packagit\ArticleApi\Database\Seeders\DatabaseSeeder] does not exist.
    
    

    感觉是找错了路径...

    大佬的包挺好用的...我试着写控制器和路由没问题~~很舒服

    Reviewed by duolabmeng6 at 2022-06-05 07:34
A lightway implementation of Laravel's belongs To many

A lightweigth implementation of Laravel's belongs To many relationship in cases you don't need pivot table.

Feb 8, 2022
Reproduction of Belongs To Many Timestamp Isssue

Belongs to Many Issue This repository was created to demonstrate issue reported at: https://github.com/laravel/framework/issues/39727 The build fails,

Nov 23, 2021
Manage your staff from one place. Featuring Staff leave management 🏖, payslips 💵 generation & emailing, messaging 📨and more 🛠! Built with ❤️ with Laravel

Staff Management System This little buddy can help you manage your staff database! Built with ?? with Laravel #FEATURES 1 Staff management/ database S

Jun 10, 2022
Generates and handles Modules for Laravel
Generates and handles Modules for Laravel

L5Modular Keep Your Laravel App Organized This package allows you to organize your Laravel project in a modular manner. You can simply drop or generat

Apr 26, 2022
Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.
Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.

Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and

Apr 6, 2022
Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration.
Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration.

Migrator Migrator is a GUI migration manager for Laravel which you can create, manage and delete your migration. Installation: To install Migrator you

Jun 28, 2022
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

hirwa-products-plugin If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

Nov 25, 2021
Laravel Restaurant Management System Project

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Mar 26, 2022
undefined is an issue tracking product that allows agile project management.
undefined is an issue tracking product that allows  agile project management.

undefined is an issue tracking product that allows agile project management. Our goal is to make work life simpler, more efficient and stress-free. In

Jun 27, 2021
Listingslab Public CDN & Project Management

Listingslab Public CDN & Project Management pingpong ______ _ ____ | ___ (_)

Jan 2, 2022
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.

What is GitScrum? GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivit

Jun 28, 2022
👀 Manage your views in Laravel projects through artisan
👀 Manage your views in Laravel projects through artisan

Artisan View This package adds a handful of view-related commands to Artisan in your Laravel project. Generate blade files that extend other views, sc

Jun 24, 2022
Manage self-hosted Google Fonts in Laravel apps
 Manage self-hosted Google Fonts in Laravel apps

This package makes self-hosting Google Fonts as frictionless as possible for Laravel users. To load fonts in your application, register a Google Fonts embed URL and load it with the @googlefonts Blade directive.

Jun 27, 2022
A simple package to manage the creation of a structure composed of the service and repository layers in a Laravel application
A simple package to manage the creation of a structure composed of the service and repository layers in a Laravel application

Chapolim Este projeto tem como objetivo fornecer alguns comandos adicionais à interface de linha de comando do Laravel, o Artisan, para manipular a es

May 10, 2022
A Laravel package to manage versions of endpoints in an elegant way

API version control A Laravel package to manage versions of endpoints in an elegant way Two ways to manage the versions of your endpoints Option 1: Ve

Jun 25, 2022
This repo is for the Laracon 2021 talk "Manage SEO with Laravel and Nova"

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Sep 13, 2021
The api help to manage wso2 users from laravel application

Laravel WSO2 Identity API User This is a Laravel library to manage WSO2 IDP users. Installation You can install the package via composer: composer req

Dec 12, 2021
Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts
Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts

Podcastwala Your very own Podcast web app built with Laravel 5. This web app enables you to manage RSS feeds for your favorite podcasts and listen to

May 3, 2022
1Pilot.io, a universal dashboard to effortlessly manage all your Laravel applications
1Pilot.io, a universal dashboard to effortlessly manage all your Laravel applications

Website · Free Trial · Pricing · Documentation · API · Feedback · Support [You] What are you, strange being? [1Pilot] Greetings, traveller. I am 1Pilo

Mar 30, 2022