1. Go to this page and download the library: Download jkuchynka/laravel-modular 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/ */
namespace App\Posts;
use Modular\Module;
class PostsModule extends Module
{
// The unique key of the module
protected $key = 'posts';
// The display name of the module
protected $name = 'Posts';
protected $description = 'Posts Module!!!';
protected $version = '1.0';
// Module config, can be overridden by other modules and app
public function config(): array
{
return [
'some_config_var' => true,
'dependsOn' => ['users']
];
}
// Module routes
public function routes(): array
{
return [
// This is a route group
[
'prefix' => 'api',
'middleware' => ['api'],
'routes' => [
['uri' => '', 'method' => 'api-resource']
]
]
];
}
}
$modular = app(\Modular\Modular::class);
$users = $modular->getModule('users');
// Get module name
echo $users->name;
// Get all config vars
dump($users->getConfig());
// Get a config var with default
echo $users->get('some_var', 'foo');