Giter VIP home page Giter VIP logo

laravel-modules's Introduction

Abandoned

This package is no longer maintained.

I encourage you to use composer packages for your modules to get the most flexibility out of it.

Modules in Laravel 4

Application specific modules in Laravel 4 can be enabled by adding the following to your "composer.json" file:

"require": {
    "creolab/laravel-modules": "dev-master"
}

And by adding a new provider to your providers list in "app/config/app.php":

'providers' => array(
    'Creolab\LaravelModules\ServiceProvider',
);

Also you need to add your modules directory to the composer autoloader:

"autoload": {
    "classmap": [
        "app/modules"
    ]
}

This also means you need to run "composer dump-autoload" every time you add a new class to your module.

By default you can add a "modules" directory in your "app" directory. So as an example this is a structure for one of my projects:

app/
|-- modules
    |-- auth
        |-- controllers
        |-- models
        |-- views
        |-- module.json
    |-- content
        |-- controllers
        |-- models
        |-- views
        |-- module.json
    |-- shop
        |-- module.json
    |-- system
        |-- module.json

Note that every module has a "module.json" file, in which you can enable/disable the module. I plan on adding more meta data to these module definitions, but I need feedback as to what to put in there. The first thing will probably be some kind of a bootstrap class.

If you want to have your modules in more that 1 directories you need to change the packages config file as following:

'path' => array(
    'app/modules',
    'public/site',
    'another/folder/containing/modules',
),

And don't forget to add those directories to your autoload list inside the composer.json file.

One of the available option is the order in which the modules are loaded. This can be done simply by adding the following to your module.json file:

"order": 5

The order defaults to 0, so keep that in mind if you don't define it.

For now take a look at the example implementation, and please provide feedback ;)

https://github.com/bstrahija/laravel-modules-example

Commands

There are 2 commands available through this package:

php artisan modules

Which simply diplays all current modules depending on the mode set in the configuration. And:

php artisan modules:scan

Which is only required if you have your modules setup in the "manifest" mode (see below). This command scans the modules exactly like in the "auto" mode, but caches the results into a manifest file.

Optimization

By default the package scans the "modules" directory for "module.json" files. This is not the best solution way to discover modules, and I do plan to implement some kind of a caching to the Finder class. To optimize the modules Finder even more you can publish the package configuration, and add the modules and definitions directly inside the configuration file by running:

php artisan config:publish creolab/laravel-modules

And the editing the file "app/config/packages/creolab/laravel-modules/config.php". You just need to change the "mode" parameter from "auto" to "manual", and list your modules under the "modules" key. An example of that is already provided inside the configuration.

Note for Manual mode with multiple paths : Laravel-Modules could not determine witch path to use. So please specify the folder containing the module you want to load. Like this example :

'modules' => [
    'app/modules' => [
        'system' => ['enabled' => true],
    ],
    'another/modules/path' => [
        'pages' => ['enabled' => false],
        'seo'   => ['enabled' => true],
    ],
],

You can also add multiple module paths as an array, but do note that if a module has the same name, there will be problems.

Including files

You can also specify which files in the module will be automatically included. Simply add a list of files inside your module.json config:

{
    "include": [
        "breadcrumbs.php"
    ]
}

There are some defaults set on which files will be included if they exist. Take a look at the latest config file, and republish the configuration if needed. By default these files will be included:

'include' => array(
    'helpers.php',
    'filters.php',
    'composers.php',
    'routes.php',
    'bindings.php',
    'observers.php',
)

So you have the choice to either add your custom files to the global configuration, which will look for these files in every module, or you can set it up on a per module basis by adding it to the module.json file.

Service providers

A new addition is registering service providers for each module. Just add a line to your module.json file that looks something like this:

"provider": "App\\Modules\\Content\\ServiceProvider"

These service provider classes work exactly like any other service provider added to your app/config/app.php configuration, so setup these classes by extending the \Illuminate\Support\ServiceProvider class and adding the appropriate methods.

You can also register multiple providers for every module by simply providing an array:

"provider": [
    "App\\Modules\\Content\\ServiceProvider",
    "App\\Modules\\Content\\AnotherServiceProvider"
]

Keep in mind that you may have to run composer dump-autoload so you want get error on missing classes.

Modules Manifest

Another possible mode is "manifest" which basically writes a JSON manifest file in your Laravel storage directory that contains all the modules definitions. This is only done the first time and to update the manifest file you need to either delete it, or rescan the modules via the following command:

php artisan modules:scan

Assets

Just recently the ability to publish public assets for each module has been added. Just run:

php artisan modules:publish

And all modules that contain an "assets" directory will be published to the Laravel public directory. You can also publish assets for individual modules by providing the module name:

php artisan modules:publish content

Migrations

Every module can have it's own migrations, and they need to be in the module/migrations directory. So for example if you want to create a migration that creates a user table for the auth module:

php artisan migrate:make create_users_table --path=app/modules/auth/migrations --table=users --create

And to run all module migrations do this:

php artisan modules:migrate

Or to run migrations for a specific module:

php artisan modules:migrate auth

You can also seed the database form the module if your module.json contains a seeder setting. Just pass the --seed option to the command:

php artisan modules:migrate --seed

Seeding

The modules can also have seeders. Just create the class like you would create a normal seeder, place it somewhere inside your module, and be sure to run composer dump-autoload. Then add the following to your module.json file:

"seeder": "App\\Modules\\Content\\Seeds\\DatabaseSeeder"

This setting should contain the namespace path to your seeder class. Now simply run:

php artisan modules:seed

To seed all your modules. Or you can do it for a specific module:

php artisan modules:seed content

Commands

You can add module specific commands. This is a sample artisan command file creation :

php artisan command:make <MyModuleCommandName> --path=app/modules/<MyModule>/commands --namespace=App\Modules\<MyModule>\Commands --command=modules.mymodule:mycommand

Then in the module.json add (you can also add an array if you have multiple commands) :

"command": "App\\Modules\\<MyModule>\\Commands\\MyModuleCommandName"

After a dump-autoload you can now execute modules.mymodule:mycommand from command line :

php artisan modules.mymodule:mycommand

Aliases

If you declare Facades into your modules you will like to create Aliases for your module, you can simply reference your alias in the module.json :

"alias": {
	"<MyAlias>" "App\\Modules\\<MyModule>\\Facades\\<MyFacade>"
}

License

Thi package is open-sourced software licensed under the MIT license.

laravel-modules's People

Contributors

billmn avatar bstrahija avatar deviarte avatar freezy-sk avatar ifnotfr avatar jbelcastro avatar karelv avatar noeldavies avatar piotrchludzinski avatar ptsilva avatar sloveniangooner avatar xgenvn 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

laravel-modules's Issues

Tests

Does this support tests? If so, can I simply put them into a tests folder inside each module folder?

The package only work with max 8 modules

Hello. I need help!
The package only can load max 8 modules. I do not can add more modules no will be charged.

Strangely not recognize nor the controllers nor methods.

Thank you!

Making use of generate:resource

Just a thought, since Way Generators has a generate resource command, would it be easier for when a modules gets created, the generate:resource command is called as well?

Seed with Artisan::call()

How to use seed with Artisan::call().

Somethink like this:

Artisan::call('modules:seed', array('--module' => 'service'));

Note: I know the normal way

Artisan::call('db:seed', array('--class' => 'App\\Modules\\Service\\Seeds\\DatabaseSeeder'));

Calling a module model in another module model.

I installed the package. The problem is that, My ProductCatalog model can't see my CatalogProductImage model and hence it gives me the following error:

  Symfony \ Component \ Debug \ Exception \ FatalErrorException
  Class 'CatalogProductImage' not found

I don't know the reason. Here comes the code:

ProductCatalog.php

 <?php namespace App\Modules\Product\Models;

  use Illuminate\Auth\UserInterface;
  use Illuminate\Auth\Reminders\RemindableInterface;
  use Eloquent;
  use App\Modules\Product\Models\CatalogProductImage as CatalogProductImage;

 class ProductCatalog extends Eloquent {
      protected $table           = 'catalog';
      protected $primaryKey  = 'catalogId';
      protected $connection  = 'mysql2';
      public  $timestamps        =  FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller

      public function category() {
          return $this->hasOne('CatalogCategory', 'catalogCategoryId', 'catalogCategoryId');
      }

      public function images() {
         return $this->hasMany('CatalogProductImage', 'catalogId');
     }
  }

CatalogProductImage.php

 <?php namespace App\Modules\Product\Models;

   use Illuminate\Auth\UserInterface;
  use Illuminate\Auth\Reminders\RemindableInterface;
  use Eloquent;

  class CatalogProductImage extends Eloquent {

 protected $table            = 'catalog_image';
     protected $primaryKey  = 'catalogImageId';
 protected $connection   = 'mysql2';
     public $timestamps      =  FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller

      public function catalog() {
          return $this->hasMany('ProductCatalog', 'catalogId');
      }
  }

Recursive module directory scan

Hi,

I'm wondering if you're planning on fleshing out the module scaning to recursively scan directories so there can be a bit more folder structure to the modules without having to register each path in the config.

I've tried playing about with it but I'm getting a 404 Exception somewhere between the 2nd and end of modules scanning. None of the routes are getting registered.

I was basically extracting the meat of the Finder->scan() into a loadModules() and then when you check for modules.json, if its false (ie not a module but a folder containing modules) just start diving into the directories.

May play around a bit more when I'm more awake and provide code samples.

Migrate rollback or reset gives 'Class not found' error

I have a problem with the default php artisan migrate:rollback or php artisan migrate:reset. Probably same issue with refresh

I get the following when executing it.

PHP Fatal error:  Class 'CreateExampleTable' not found in .../vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php on line 29

Seems like a namespace issue. I tried adding a namespace in the top of the migration class file. But no luck.
Anyone having this issue?

Problem with modules:publish module

If the module don't exists return an error:
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to a member function path() on a non-object","file":"D:
xampp\htdocs\Laravel\vendor\creolab\laravel-modules\src\Creolab\LaravelModules\ModulesPublishCommand.php","line":63}}

To fix: check if the module to publish if exists.

Order of modules

Was wondering if there is any way of ordering modules. One module in my app is being processed before the other and I'd love to switch that around.

Any idea?

[Proposal] Add a module_asset() function

Hello,

Just a message to discuss about adding a module_asset() helper function.

While publishing module asset is working well, accessing is -i think- very very verbose and not productive.

Something like :

asset('packages/module/my_module/assets/css/style.css')

Could be changed to :

module_asset('my_module', 'css/style.css')

I think we do not have to know how the asset is published, just the asset is available for this module with a simple function.

What do you think about it ?

Module ServiceProvider is not registered in manual mode

module service provider file

    $this->app->booting(function()
    {
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();

        $loader->alias('MenuCategoryModel', 'App\Modules\Menu\Facades\MenuCategoryModelFacade');
    });

module.json file

   {
       "enabled" : true,
       "order"   : 1,
       "provider": "App\\Modules\\Menu\\ServiceProvider"
   }

when switching to auto mode, i can use the facade, but in the manual mode i get a class not found

Prefix module name with the module routes.

I was wondering if there is any way to prefix the module name to the routes to maintain uniqueness.

Let say i have modules staff and users and both has the same route called users. In that case the one will override the other one. If we can prefix the module directory name before the route it will become unique by itself

staff/users
users/users

Complete app directory in modules

Can you put everything from the app directory like the database directory with migrations in a module?

Thanks for this module project good idea.

Are modules automatically registered ?

Hi,

I am using several modules and for each module a service provider class is defined as described in the documentation.

I have e.g. a module 'Category' and if i reference it inside a view I would like to use the provided Facade name 'Category' but that throws a 'class Category not found'. If i use 'App\Modules\Category\Models\Category' in the view then it works but that's a bit tedious.

If i however add 'App\Modules\Category\ServiceProvider' to the providers array in app/config/app.php then i can as expected just use the class 'Category' inside the view.

But does this mean i have to add the service provider classes for each module to the providers array to be able to use the Facade name? I was under the impression that the service providers for each module would be automatically registered at run time and it would suffice just to add Creolab\LaravelModules\ServiceProvider to the providers array, unless i am mistaking..?

Thanks for your reply.

Get list of modules in a view composer

Hi.

I'm trying to get a list of the modules in a view composer, so I can generate a navigation menu of all modules.

In app/filters.php I put the following code

View::composer('nav', function($view)
{
    var_dump($app->modules->modules()->all());
});

but I got an Undefined variable: app error.
If i put the same code in app/views/layouts/master.blade.php, it works.

How can I get this data in a view composer?

Thanks!

Custom Files

I had to modify the package to accept a breadcrumbs.php so I can have two with separate templates for admin/public.

// Require module breadcrumbs.php
$breadcrumbs = $this->path('breadcrumbs.php');
if ($this->app['files']->exists($breadcrumbs)) require $breadcrumbs;

Which led me to wonder if custom files per module would be something for the json or some other solution? Maybe it is already possible and I missed it.

The package is https://github.com/davejamesmiller/laravel-breadcrumbs

[Proposal] Beautify module.json

What about beautify JSON content of module.json?
It can be more readable and fastest to modify.

My idea is to use JSON_PRETTY_PRINT in json_encode like:

$definition = json_encode(array('enabled' => true), JSON_PRETTY_PRINT);

Or better ... using PHP version check (because this constant is introduced in PHP 5.4) :

$definition = json_encode(array('enabled' => true), (version_compare(PHP_VERSION, '5.4.0', '>=') ? false : JSON_PRETTY_PRINT));

Thoughts?

Modules Manager Interface

I am suggesting to add interface for module management feature. I am wondering if you will database approach to register modules and enable/disable them via admin panel or you'll use the current structure.

BR

The directory "app/modules" does not exist.

A quick issue:

If you install the laravel-modules and include the service provider in the app.php and don't create the folder "app/modules", you get an error when trying to do anything with the artisan.

Perhaps it would be best if you could do a check on the directory existance.

Feature Request: publish assets in a folder named from origin

Hi,

i use following config:

    /**
     * The path that will contain our modules
     * This can also be an array with multiple paths
     */
    'path' => array(
        'modules',
        'portlets'
    ),

When i publish the assets from the module or portlets folder all will be published inside packages module...
It will bei nicer if the origin folder will be published in public:

Example:

I have a module in "modules/Sample1" . When i publish the assets it should be placed in "public/packages/modules/modules/Sample1" and...

the asstes of the module inside "portlets/Sample2" should be placed in "public/packages/modules/portlets/Sample2"

Bye, René

Load multiple modules

Hello,

Is it possible to use this package to load multiple modules at the same time?

What i want to achieve is a widget system where the whole app consists of modules.

Example:

This is meant to be a dashboard with different widgets and i want every widget to be a module.

Assci-art-example: http://paste.laravel.com/13jY

//Tim

Module Includes

Is there anyway to make the module includes /add/ to the array rather than overriding it from the default one?

Seeds

Hi there,

I have been using modules extensively and was wondering if you are planning on a
modules:seed command?

best regards

Module views extends layout in app/views folder

What if i have the main layout view in app/views/layout/master.blade.php and in the apps/modules/blog/views/ folder i have a view index.blade,php and i want it to extend master.blade.php how would i write that.

I tried @extends('layout.master'), but did not work.

Thank you

No hint path defined for [dashboard].

I'm just update to latest master-dev. Now, i got "No hint path defined for [xyz]" exception.
This exception throw from View::make('xyz::template'). Thanks

Adding dependencies to modules

It would be nice if dependencies could be defined. Such as: the Messaging module needs the User module, perhaps even with a specific version like is being done with composer.json.

Infinite loop when using migrate:reset --pretend

Whenever I use php artisan migrate:reset --pretend I get a never ending output of Content: drop table wr_pages`` where wr_pages is just simple a Schema::drop ( 'pages' );

Furthermore, it would be awesome to see something like php artisan modules:migrate --reset which would not reset the migrations of my normal app.

Finally: thanks for making this package, it makes life quite a lot easier :)!

laravel-modules breaks during artisan optimization

~/Documents/PhpStorm/AuthPilot(branch:master*) » php artisan
# Command works

~/Documents/PhpStorm/AuthPilot(branch:master*) » php artisan optimize
Generating optimized class loader

~/Documents/PhpStorm/AuthPilot(branch:master*) » php artisan
{
   "error":{
      "type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException",
      "message":"Class 'Creolab\\LaravelModules\\ServiceProvider' not found",
      "file":"\/Users\/devil\/Documents\/PhpStorm\/AuthPilot\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php",
      "line":158
   }
}

Being able to use optimize would be extremely helpful as well.

No hint path defined for [core].

Hi first of all i really like your package. One thing what i encounterd.

Everything is autoloaded correctly.

I have the following folder structure

  • Core
    • controllers
    • models
    • views

routes.php
module.json

And when i load my view

$this->layout->content = View::make('core::users.index')

i get the following error
No hint path defined for [core].

Could you please give me a hint what i am doing wrong?

permissions

Can you please change the permissions from 0755 to 0775 or at least make it a config option.

  • Side note - you may want to put in the docs that module:generate depends on way/generators... took me a bit to work this out :(

Module outside application path

Hey, mate.

Me again.

So, I am doing a CMS which has multiple instances and I'd love to make my base module central, so in case of any changes it can only be changed in one place and it affects all instances.

The idea I was having was if it is possible to enlist a folder for modules outside of the application folder.

I have tried changing the base_path() to realpath() in the Finder.php (line 98) which actually finds the module outside but seems to break down the loading of the modules (guessing they are loaded with the relative path).

You have any idea how I could achieve that (to load them outside of application) and if you could add it to the package configuration).

Thanks for your reply.

Getting NotFoundHttpException on module routes

I have followed the instructions and no matter what I do, all I get is the NotFoundHttpException whoops page.

When I tried copy-pasting your example package into a new install, it worked - but as soon as I tried changing the name of the "content" module to something else (including changing all namespaces, references in routes, module.json files, etc. and performing composer and artisan dumps), I had the same issue.

Is there something I'm missing that is telling Laravel to use "content" as the default module or perhaps something else going on? (I'd be happy to send you my codebase if it would help).

Just a small ideea

Why don;t you putt into the manual that is posible to create a module from composer?
I was using your examples and got only errors, and i started again, clean instalation, then the modules package and still errors. So i tried this on command line:
php artisan modules:create mymodule
And worked.
BTW great tool here.

[Proposal] multiple seeders per module

Hi.
This is a great package and I use it always ;).
I think it would be good if we could have multiple seeders per module.
If we set array for seeder in module.json for example

{
    "enabled": true,
    "seeder": [
        "Product\\Seeds\\ProductsSeeder",
        "Product\\Seeds\\AttributesSeeder"
    ]
}

There is little modification of Module.php:

    public function seed()
    {
        $classes = $this->def('seeder');

        foreach((array)$classes as $class){
           if (class_exists($class))
           {
               $seeder = new $class;
               $seeder->run();
           }
        }
    }

Thanks

Bug

There's a major bug in this package it's to good lol. I see that you have came a long way since I made a suggestion about adding migrations in. Just wanted to say keep up the great work. Thanks.

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.