style updates
This commit is contained in:
@@ -4,13 +4,24 @@ use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void { Schema::create('forms', function (Blueprint $table): void { $table->id();
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('forms', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('slug');
|
||||
$table->text('description')->nullable();
|
||||
$table->json('schema')->nullable();
|
||||
$table->boolean('enabled')->default(true);
|
||||
$table->timestamps(); $table->softDeletes(); }); }
|
||||
public function down(): void { Schema::dropIfExists('forms'); }
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('forms');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,20 +10,57 @@ use Modules\Forms\Models\Form;
|
||||
|
||||
final class FormController extends Controller
|
||||
{
|
||||
public function index(): View { return view('forms::admin.index', ['records' => Form::query()->latest()->paginate(20)]); }
|
||||
public function create(): View { return view('forms::admin.form'); }
|
||||
public function store(Request $request): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
public function index(): View
|
||||
{
|
||||
return view('forms::admin.index', ['records' => Form::query()->latest()->paginate(20)]);
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('forms::admin.form');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'schema' => ['nullable', 'array'],
|
||||
'enabled' => ['sometimes', 'boolean']]); if ($request->filled('schema_json')) { $data['schema'] = json_decode($request->string('schema_json')->toString(), true, 512, JSON_THROW_ON_ERROR); }
|
||||
$data['enabled'] = $request->boolean('enabled'); Form::create($data); return redirect()->route('forms.index')->with('status', 'Form created.'); }
|
||||
public function edit(Form $form): View { return view('forms::admin.form', ['record' => $form]); }
|
||||
public function update(Request $request, Form $form): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
'enabled' => ['sometimes', 'boolean']]);
|
||||
if ($request->filled('schema_json')) {
|
||||
$data['schema'] = json_decode($request->string('schema_json')->toString(), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$data['enabled'] = $request->boolean('enabled');
|
||||
Form::create($data);
|
||||
|
||||
return redirect()->route('forms.index')->with('status', 'Form created.');
|
||||
}
|
||||
|
||||
public function edit(Form $form): View
|
||||
{
|
||||
return view('forms::admin.form', ['record' => $form]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Form $form): RedirectResponse
|
||||
{
|
||||
$data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'schema' => ['nullable', 'array'],
|
||||
'enabled' => ['sometimes', 'boolean']]); if ($request->filled('schema_json')) { $data['schema'] = json_decode($request->string('schema_json')->toString(), true, 512, JSON_THROW_ON_ERROR); }
|
||||
$data['enabled'] = $request->boolean('enabled'); $form->update($data); return redirect()->route('forms.index')->with('status', 'Form updated.'); }
|
||||
public function destroy(Form $form): RedirectResponse { $form->delete(); return back()->with('status', 'Form deleted.'); }
|
||||
'enabled' => ['sometimes', 'boolean']]);
|
||||
if ($request->filled('schema_json')) {
|
||||
$data['schema'] = json_decode($request->string('schema_json')->toString(), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
$data['enabled'] = $request->boolean('enabled');
|
||||
$form->update($data);
|
||||
|
||||
return redirect()->route('forms.index')->with('status', 'Form updated.');
|
||||
}
|
||||
|
||||
public function destroy(Form $form): RedirectResponse
|
||||
{
|
||||
$form->delete();
|
||||
|
||||
return back()->with('status', 'Form deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,16 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
final class Form extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $table = 'forms';
|
||||
protected $fillable = ['name', 'slug', 'description', 'schema', 'enabled'];
|
||||
|
||||
protected function casts(): array { return [
|
||||
'schema' => 'array',
|
||||
'enabled' => 'boolean'
|
||||
]; }
|
||||
|
||||
protected $table = 'forms';
|
||||
|
||||
protected $fillable = ['name', 'slug', 'description', 'schema', 'enabled'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'schema' => 'array',
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,15 @@
|
||||
|
||||
namespace Modules\Forms\Support;
|
||||
|
||||
final class ModuleInfo { public static function name(): string { return 'Forms'; } public static function nameLower(): string { return 'forms'; } }
|
||||
final class ModuleInfo
|
||||
{
|
||||
public static function name(): string
|
||||
{
|
||||
return 'Forms';
|
||||
}
|
||||
|
||||
public static function nameLower(): string
|
||||
{
|
||||
return 'forms';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
it('registers the Forms administration route', function (): void { expect(Route::has('administration.forms.index'))->toBeTrue(); });
|
||||
it('registers the Forms administration route', function (): void {
|
||||
expect(Route::has('administration.forms.index'))->toBeTrue();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user