PHP code example of pierresilva / laravel-modules

1. Go to this page and download the library: Download pierresilva/laravel-modules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pierresilva / laravel-modules example snippets


pierresilva\Modules\ModulesServiceProvider::class,

'Module' => pierresilva\Modules\Facades\Module::class,

'path' => app_path('Modules'),

'namespace' => 'App\Modules\\'

'pathMap' => [
    'Database'          => 'src/Database',
    'Http'              => 'src/Http',
    'Providers'         => 'src/Providers',
    'Models'            => 'src/Models',
    'Policies'          => 'src/Policies',
    'Resources/Views'   => 'resources/views',
    'Resources/Lang'    => 'resources/lang',
    'Routes'            => 'routes',
],

Route::get('admin', function() {
    return view('blog::admin');
});

echo trans('blog::messages.welcome');

/**
 * Preforms post-registration booting of services.
 *
 * @return void
 */
public function boot()
{
    $this->publishes([
        __DIR__.'/../Assets' => public_path('assets/modules/example'),
    ], 'modules');
}

protected $routeMiddleware = [
    ...
    'module' => \pierresilva\Modules\Middleware\IdentifyModule::class,
];

Route::group(['prefix' => 'blog', 'middleware' => ['module:blog']], function() {
    Route::get('/', function() {
        dd(
            'This is the Blog module index page.',
            session()->all()
        );
    });
});

$modules = Module::all();

$modules = Module::slugs();

$blogModule = Module::where('slug', 'blog');

$orderedModules = Module::sortBy('order');

$orderedModules = Module::sortByDesc('order');

if (Module::exists('blog')) {
    return 'Module "blog" exists!';
}

$moduleCount = Module::count();

$moduleProperties = Module::getProperties('blog');

   $moduleName = Module::get('blog::name', 'Blog');
   

Module::set('blog::description', 'This is a new description for the blog module.');

Module::enable('blog');

Module::disable('blog');

$enabledModules = Module::enabled();

$disabledModules = Module::disabled();

if (Module::isEnabled('blog')) {
    return 'Blog module is enabled!';
}

if (Module::isDisabled('blog')) {
    return 'Blog module is disabled.';
}

laravel-project/
    app/
    |-- Modules/
        |-- Blog/
            |-- Config/
            |-- Database/
                |-- Factories/
                |-- Migrations/
                |-- Seeds/
            |-- Http/
                |-- Controllers/
                |-- Middleware/
                |-- Requests/
            |-- Models/
            |-- Providers/
                |-- ModuleServiceProvider.php
                |-- RouteServiceProvider.php
            |-- Resources/
                |-- Lang/
                |-- Views/
            |-- Routes/
                |-- api.php/
                |-- web.php/
            |-- Tests/
            |-- module.json

php artisan vendor:publish

php artisan vendor:publish --tag=modules --force
html
"This is the Blog module index page."
array:2 [▼
  "_token" => "..."
  "module" => array:6 [▼
    "name" => "Blog"
    "slug" => "blog"
    "version" => "1.0"
    "description" => "This is the description for the Blog module."
    "enabled" => true
    "order" => 9001
  ]
]

php artisan module:make blog

php artisan module:make:controller blog PostsController

php artisan module:make:seeder blog PostsTableSeeder

php artisan module:make:request blog CreatePostRequest

php artisan module:enable blog

php artisan module:migrate

php artisan module:migrate:refresh

php artisan module:migrate:rollback

php artisan module:migrate:rollback blog

php artisan module:seed

php artisan module:seed blog