Coder Social home page Coder Social logo

laravel_module_manager's Introduction

Laravel Module Manager

Introduction

When you work on small project, you will feel laravel default structure is enough. When your project grows up, you will think to divide your app into modules where each module will contain all of it resources such as Controllers, Models, Views, Migrations, Config etc. This laravel-module-manager package will help you to manage laravel modular application easily.

Installation

  • laravel 5.4 or 5.5

    composer require mrabbani/laravel-module-manager
    
  • Laravel 5.3, Add the following line to your composer.json file and run composer install in your terminal.

    "mrabbani/laravel-module-manager": "^1.4"
    

If you are using Laravel<5.5 you have to add module manager service provider to config/app.php file

Mrabbani\ModuleManager\Providers\ModuleProvider::class,

To create new module run the bellow command:

php artisan module:create name-of-your-module
php artisan module:install {module_alias_name}

Folder Structure

If your module name is module1 the module structure will be

Module Structure

Configuration

By default, all of your module will be placed inside modules directory into your application's base directory. If you want to change publish module_manager config file by

php artisan vendor:publish

Now you can change the default modules directory by changing module_directory value of config/module_manager.php file.

Available Commands

To see all module related commands run php artisan into terminal. Available commands are:

  • php artisan module:create {alias}
  • php artisan module:make:controller {alias} {ControllerName}
  • php artisan module:make:controller {alias} {ControllerName} --resource
  • php artisan module:make:command {alias} {CommandName}
  • php artisan module:make:facade {alias} {FacadeName}
  • php artisan module:make:middleware {alias} {MiddlewareName}
  • php artisan module:make:migration {alias} {migration_name} --create --table=table_name
  • php artisan module:make:migration {alias} {migration_name} --table=table_name
  • php artisan module:make:model {alias} {ModelName}
  • php artisan module:make:provider {alias} {ProviderName}
  • php artisan module:make:request {alias} {RequestName}
  • php artisan module:make:service {alias} {ServiceClassName}
  • php artisan module:make:support {alias} {SupportClassName}
  • php artisan module:make:seeder {alias} {SeederClassName}
  • php artisan module:db:seed {alias}
  • php artisan module:db:seed {alias} --class={SeederClassName}
  • php artisan module:migrate {alias}
  • php artisan module:migrate:rollback {alias}
  • php artisan module:routes
  • php artisan module:install {alias}
  • php artisan module:uninstall {alias}
  • php artisan module:enable {alias}
  • php artisan module:disable {alias}

'alias' is your module's alias name. you can find module's alias name in module.json file of module directory

You must install your module to activate

php artisan module:install {alias}

Loading Component

You have to load views, config and translation by following laravel package

Loading View
view(module_alias::view_file)

you may load the module1 module's index.blade.php view like so:

view('module1::index');
Loading Translation

you may load the module1 module's welcome line from the messages file like so:

trans('module1::messages.welcome');
Loading Config File

you may load the module1 module's welcome line from the messages file like so:

config('messages.welcome');

You have to merge the configurations, use the mergeConfigFrom method within your ModuleServiceProvider provider's register method:

public function register()
{
    $this->mergeConfigFrom(
        __DIR__.'/../../config/messages.php', 'messages'
    );
}
Register Middleware

You should create a MiddlewareServiceProvider provider to register your middleware dynamically.


use Illuminate\Support\ServiceProvider;

class MiddlewareServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        /**
         * @var Router $router
         */
        $router = $this->app['router'];

        $router->aliasMiddleware('middleware-shortname', MiddlewareClassName::class);
    }
}

You should register all of your module's custom provider in ModuleServiceProvider provider's register method instead application's config/app.php file.

Credit

WebEd

laravel_module_manager's People

Contributors

mrabbani avatar stoneworld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laravel_module_manager's Issues

Registering Commands

I haven't seen a way of auto-registering commands so that they are available when you run php artisan as explained here.

Please let me know if there is. Right now, i have to manually register.

how to working with phpunit?

is there any built-in command to create an manage unit tests in my modules? and if there is no command how can I run unit test of my module?

How not migrate migration?

hi , I run command :

php artisan module:migrate users
users module migrating
users module migrated

but the table is not created in the database. Why?

Not working with laravel 5.4

Hi, @mrabbani. Could you update dependencies?

Your requirements could not be resolved to an installable set of packages.

Problem 1
    - Conclusion: don't install laravel/framework v5.4.8
    - Conclusion: don't install laravel/framework v5.4.7
    - Conclusion: don't install laravel/framework v5.4.6
    - Conclusion: don't install laravel/framework v5.4.5
    - Conclusion: don't install laravel/framework v5.4.4
    - Conclusion: don't install laravel/framework v5.4.3
    - Conclusion: don't install laravel/framework v5.4.2
    - Conclusion: don't install laravel/framework v5.4.1
    - mrabbani/laravel-module-manager v1.03 requires illuminate/database 5.3.* -> satisfiable by laravel/framework[v5.3.30], illuminate/database[v5.3.0, v5.3.16, v5.3.23, v5.3.4].
    - mrabbani/laravel-module-manager v1.02 requires illuminate/database 5.3.* -> satisfiable by laravel/framework[v5.3.30], illuminate/database[v5.3.0, v5.3.16, v5.3.23, v5.3.4].
    - mrabbani/laravel-module-manager v1.03 requires illuminate/database 5.3.* -> satisfiable by laravel/framework[v5.3.30], illuminate/database[v5.3.0, v5.3.16, v5.3.23, v5.3.4].
    - Can only install one of: laravel/framework[v5.4.0, v5.3.30].
    - don't install illuminate/database v5.3.0|don't install laravel/framework v5.4.0
    - don't install illuminate/database v5.3.16|don't install laravel/framework v5.4.0
    - don't install illuminate/database v5.3.23|don't install laravel/framework v5.4.0
    - don't install illuminate/database v5.3.4|don't install laravel/framework v5.4.0
    - Installation request for laravel/framework 5.4.* -> satisfiable by laravel/framework[v5.4.0, v5.4.1, v5.4.2, v5.4.3, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8].
    - Installation request for mrabbani/laravel-module-manager ^1.02 -> satisfiable by mrabbani/laravel-module-manager[v1.02, v1.03].

laravel 5.7

hi i want to work with your package but it doesn't support on laravel 5.7
can you help me?

json translations not working

Do translation files like modules/modulename/resources/lang/de.json (loaded by ModuleProvider->boot $this->loadJSONTranslationsFrom) work for you?

I can't get any translations like __('Hello world') in module's blade files and routes to work. No error, but it just won't translate for me.

Translations loaded by loadTranslationsFrom works fine, so just the json ones don't.

Any idea how I could get the json translations to work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.