1. Go to this page and download the library: Download javadle/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/ */
'generator' => [
'components' => [
'config' => true, // Создать config/config.php
'command' => true, // Создать папку для команд
'migration' => true, // Создать папку для миграций
'seeder' => true, // Создать папку для сидеров
'factory' => true, // Создать папку для фабрик
'model' => true, // Создать папку для моделей
'controller' => true, // Создать папку для контроллеров
'filter' => true, // Создать папку для middleware
'request' => true, // Создать папку для requests
'provider' => true, // Создать папку для провайдеров
'lang' => true, // Создать папку для переводов
'views' => true, // Создать папку для views
'test' => false, // Создать папку для тестов
'event' => false, // Создать папку для событий
'listener' => false, // Создать папку для слушателей
'policies' => false, // Создать папку для политик
'rules' => false, // Создать папку для rules
'jobs' => false, // Создать папку для jobs
'resource' => false, // Создать папку для API resources
],
],
'paths' => [
'controller' => 'src/Http/Controllers', // Путь к контроллерам
'model' => 'src/Models', // Путь к моделям
'migration' => 'database/migrations', // Путь к миграциям
// ... и другие
],
use JavaDLE\Modular\Facades\Module;
// Проверка существования
if (Module::has('Blog')) {
// Модуль существует
}
// Проверка статуса
if (Module::isEnabled('Blog')) {
// Модуль включен
}
// Получить модуль
$blog = Module::find('Blog');
echo $blog->getName();
echo $blog->getPath();
// Управление статусом
Module::enable('Blog');
Module::disable('Blog');
// Получить коллекции
$all = Module::all(); // Все модули
$enabled = Module::getEnabled(); // Только включенные
$disabled = Module::getDisabled(); // Только выключенные
// Удалить модуль
Module::delete('Blog');
use JavaDLE\Modular\Contracts\RepositoryInterface;
class ModuleController
{
public function __construct(
private RepositoryInterface $modules
) {}
public function index()
{
$modules = $this->modules->all();
return view('modules.index', compact('modules'));
}
}
// В контроллере
return view('blog::index');
return view('blog::posts.show', ['post' => $post]);
// В Blade
@extends('blog::layouts.master')
@section('content')
<h1>{{ __('blog::messages.welcome') }}</h1>
@endsection
// resources/lang/en/messages.php
return [
'welcome' => 'Welcome to Blog',
'posts' => 'Posts',
];
// Использование
__('blog::messages.welcome');
trans('blog::messages.posts');
bash
# 1. Создать модуль
php artisan module:make Blog
# 2. Создать компоненты
php artisan module:make-model Blog Post
php artisan module:make-controller Blog PostController
php artisan module:make-migration Blog create_posts_table
# 3. Запустить миграции
php artisan migrate
# 4. Использовать
# - Views: view('blog::index')
# - Routes: route('blog.index')
# - Translations: __('blog::messages.welcome')
# - Config: config('module.blog.posts_per_page')
bash
# 1. Создать модуль с Filament поддержкой
php artisan module:make Shop --filament
# 2. Создать Filament компоненты
php artisan module:make-filament-resource Shop Product
php artisan module:make-filament-page Shop Settings
php artisan module:make-filament-widget Shop SalesChart
# 3. Готово! Filament автоматически обнаружит ресурсы
bash
# 1. Создать модуль
php artisan module:make Api
# 2. Создать API компоненты
php artisan module:make-controller Api ProductApiController
php artisan module:make-resource Api ProductResource
php artisan module:make-request Api StoreProductRequest
# 3. Настроить routes/api.php
Route::apiResource('products', ProductApiController::class);