Skip to content

Commit 342840c

Browse files
Muhannad ShellehMuhannad Shelleh
authored andcommitted
Initial version
1 parent 55674e7 commit 342840c

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,54 @@ Modules management library for laravel 5.1
33

44
Allows modules structure of your project. Each module can have its views, config, routes, controllers, ...
55

6+
## Installation
7+
1. The package relies on the composer PSR-4 loader like all laravel projects. Use the composer command:
8+
```
9+
composer require itvisionsy/laravel-modules
10+
```
11+
1. Add `\ItvisionSy\Laravel\Modules\ServiceProvider::class` to providers section in your `config/app.php` file:
12+
```php
13+
'providers'=>[
14+
//...
15+
\ItvisionSy\Laravel\Modules\ServiceProvider::class,
16+
],
17+
```
18+
1. Publish the config file using the command
19+
```
20+
php artisan vendor:publish
21+
```
22+
This will copy the `modules.php` config file to your `config` folder.
23+
1. Modify the `config/modules.php` config file as needed.
24+
25+
## How It Works
26+
Your modules should go in a root modules folder. By default this is `app/Modules` which maps to the namespace
27+
`\App\Modules`.
28+
29+
Each of your modules will have its own folder inside the modules root folder, the folder will be named after the module
30+
name, and will map to the namespace `\App\Modules\{ModuleName}`.
31+
32+
Each module will contain a base module definition class, which (by default) will be named `Module.php` and maps to
33+
the namespace `\App\Modules\{ModuleName}\Module`. This class will act as the key generator for the module URLs, routes,
34+
and other framework-related values.
35+
36+
Each module will contain its data models, controllers, views, routes, and other project files as usual. The `composer`
37+
PSR-4 loader should take care of loading your module files and classes properly.
38+
39+
Your module controllers (by default go into the `Http/Controllers` folder) should inherite the
40+
`ItvisionSy\Laravel\Modules\Controller` class to make views rendering and other tasks easier.
41+
42+
## Creating Modules
43+
To create a new module, you can use the artisan command
44+
```
45+
php artisan modules:make {id} {name} [--url={url}]
46+
```
47+
Values of `id`, `name`, and `url` are strings, and the URL part is optional and will be used to generate make the
48+
URLs of the module more human friendly.
49+
50+
This command will create the basic folder structure inside the modules folder, along with the base module and a sample
51+
routes (inside `Http/routes.php`), controller (inside `Http/Controllers/`), and view (inside `Views`).
52+
53+
As you have the basic structure, you can start creating your files and classes as normal. Nothing special to worry about.
54+
655
## Thanks
756
- [JetBrains](https://www.jetbrains.com/) for the free license of [PHPStorm IDE](https://www.jetbrains.com/phpstorm/specials/phpstorm/phpstorm.html). The great tool I wrote this module with.

config/defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* If you want to use a closure, in your kernel.php call the
3131
* \ItvisionSy\Laravel\Modules\Modules::setStoreHandler(closure())
3232
*/
33-
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler::class,
33+
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\DummyStoreHandler::class,
3434
/*
3535
* If you do not provide a store handler, then the following connection will be used to store the settings for you.
3636
* You will need to initiate the required table by issuing the modules:db:init command.
@@ -44,7 +44,7 @@
4444
/*
4545
* True will make the default status of the modules is enabled if the store can not find an entry for the module
4646
*/
47-
'modules_enabled_by_default' => false,
47+
'modules_enabled_by_default' => true,
4848

4949

5050
/**-----------------------------------------------------------

config/published.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* If you want to use a closure, in your kernel.php call the
3131
* \ItvisionSy\Laravel\Modules\Modules::setStoreHandler(closure())
3232
*/
33-
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\SimpleDbStoreHandler::class,
33+
'store_handler' => \ItvisionSy\Laravel\Modules\StoreHandlers\DummyStoreHandler::class,
3434
/*
3535
* If you do not provide a store handler, then the following connection will be used to store the settings for you.
3636
* You will need to initiate the required table by issuing the modules:db:init command.
@@ -44,7 +44,7 @@
4444
/*
4545
* True will make the default status of the modules is enabled if the store can not find an entry for the module
4646
*/
47-
'modules_enabled_by_default' => false,
47+
'modules_enabled_by_default' => true,
4848

4949

5050
/**-----------------------------------------------------------

0 commit comments

Comments
 (0)