modules init/deactivate, modules migrations

This commit is contained in:
2024-09-23 12:50:50 +03:00
parent f20ba63277
commit 9e2f7cd9e3
20 changed files with 304 additions and 32 deletions

View File

@ -2,13 +2,29 @@
namespace kernel\modules\post;
use kernel\helpers\Debug;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
class PostModule extends Module
{
public function init()
public MenuService $menuService;
public function __construct()
{
// TODO: Implement init() method.
$this->menuService = new MenuService();
}
public function init(): void
{
$this->menuService->createItem([
"label" => "Посты",
"url" => "/admin/post",
"slug" => "post",
]);
}
public function deactivate(): void
{
$this->menuService->removeItemBySlug("post");
}
}

View File

@ -4,5 +4,8 @@
"author": "ITGuild",
"slug": "post",
"description": "Post module",
"module_class": "PostModule"
"module_class": "kernel\\modules\\post\\PostModule",
"module_class_file": "{KERNEL_MODULES}/post/PostModule.php",
"routs": "routs/post.php",
"migration_path": "migrations"
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
\kernel\App::$db->schema->create('post', function (Blueprint $table) {
$table->increments('id');
$table->text('content')->nullable(false);
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
\kernel\App::$db->schema->dropIfExists('post');
}
};

View File

@ -0,0 +1,20 @@
<?php
use app\controllers\MainController;
use kernel\App;
use kernel\modules\admin_themes\controllers\AdminThemeController;
use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']);
App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
});
});