abivia/nextform-laravel

Abivia NextForm Generator for Laravel

1.0.2 2020-09-13 03:50 UTC

This package is auto-updated.

Last update: 2024-09-13 16:15:42 UTC


README

此软件包将 NextForm 功能集成到 Laravel 应用程序中。

有关在应用程序中使用的示例,请访问 https://gitlab.com/abivia/nextform-laravel-demo

该软件包在 resources/nextform 中查找模式和表单定义。

默认渲染引擎是 Bootstrap4。可以通过将这些设置添加到 config/view.php 来明确设置。

    'nextform' => [
        'renderer' => 'Bootstrap4'
    ],

在控制器中加载模式和填充数据的示例

    public function edit($id)
    {
        $test = Test::findOrFail($id);
        NextForm::addSchema('test-schema');
        NextForm::populate($test);

        return view('tests/edit', compact('test'));
    }

NextForm 生成表单的 HTML,同时还包括到所需的 CSS 和 JS 库的链接,以及任何特定于表单的 JS。一个基本的布局文件可能看起来像这样

layout/blade.php

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>NextForm Demo</title>
  <link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" />
  @yield('pagelinks')
</head>
<body>
  <div class="container">
    @yield('content')
  </div>
  <script src="{{ asset('js/app.js') }}" type="text/js"></script>
  @yield('script')
</body>
</html>

表单视图可能看起来像这样

edit.blade.php

@extends('../layout')
<?php
NextForm::generate(
    'test-form',
    [
        'action' => route('tests.update', $test->id),
        'state' => ['_method' => 'PATCH']
    ]
);
?>
@section('content')
    @lang('Update Tests')
    @if ($errors->any())
      <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
              <li>{{ $error }}</li>
            @endforeach
        </ul>
      </div><br />
    @endif
    <?php NextForm::body(); ?>
@endsection
@section('pagelinks')
<?php NextForm::links(); ?>
@endsection
@section('script')
<?php NextForm::scriptFiles(); ?>
<script>
<?php NextForm::script(); ?>
</script>
@endsection