admin init command
This commit is contained in:
@ -76,21 +76,20 @@ class OptionController extends AdminController
|
||||
*/
|
||||
public function actionEdit(int $id): void
|
||||
{
|
||||
Debug::prn($_REQUEST);
|
||||
$option = Option::find($id);
|
||||
if (!$option) {
|
||||
throw new \Exception('Option not found');
|
||||
}
|
||||
$optionForm = new CreateOptionForm();
|
||||
$optionService = new OptionService();
|
||||
$optionForm->load($_REQUEST);
|
||||
if ($optionForm->validate()) {
|
||||
$option = $optionService->update($optionForm, $option);
|
||||
$option = $this->optionService->update($optionForm, $option);
|
||||
if ($option) {
|
||||
$this->redirect('/admin/option' . $option->id);
|
||||
$this->redirect('/admin/option/' . $option->id);
|
||||
}
|
||||
}
|
||||
$this->redirect('/admin/option/update' . $id);
|
||||
|
||||
$this->redirect('/admin/option/update/' . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete(int $id): void
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?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('option', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('key', 255);
|
||||
$table->text('value')->nullable();
|
||||
$table->string('label', 255)->nullable();
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('option');
|
||||
}
|
||||
};
|
@ -14,6 +14,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Option extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'option';
|
||||
protected $fillable = ['key', 'value', 'label', 'status'];
|
||||
@ -29,4 +31,15 @@ class Option extends Model
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -4,16 +4,22 @@ namespace kernel\modules\option\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property string $key
|
||||
* @property string $value
|
||||
* @property string $label
|
||||
* @property integer $status
|
||||
*/
|
||||
class CreateOptionForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'admin_theme_paths' => '',
|
||||
'active_admin_theme' => '',
|
||||
'module_paths' => '',
|
||||
'active_modules' => ''
|
||||
'key' => 'required|min-str-len:1|max-str-len:50',
|
||||
'value' => '',
|
||||
'label' => '',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router){
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']);
|
||||
@ -13,5 +13,5 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']);
|
||||
});
|
||||
});
|
||||
});
|
@ -35,6 +35,20 @@ class OptionService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createFromParams(string $key, string $value, string $label): false|Option
|
||||
{
|
||||
$model = new Option();
|
||||
$model->key = $key;
|
||||
$model->value = $value;
|
||||
$model->label = $label;
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// public function createOptionArr(): array
|
||||
// {
|
||||
// foreach (Option::all()->toArray() as $option) {
|
||||
|
@ -38,7 +38,7 @@ $form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(['1', '2'])
|
||||
->setOptions(Option::getStatus())
|
||||
->render();
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user