このページの翻訳:
- 日本語 (ja)
- English (en)
最近の更新
最近の更新
composer require kris/laravel-form-builder
本当にシンプルなFormをFormBuilderで作成してみる。
Formをsubmitすると、ただリクエストを表示するだけ。
php artisan make:form Forms/SongForm --fields="name:text, lyrics:textarea, publish:checkbox"
app/Forms/SongForm.php
<?php namespace App\Forms; use Kris\LaravelFormBuilder\Form; class SongForm extends Form { public function buildForm() { $this ->add('name', 'text') ->add('lyrics', 'textarea') ->add('publish', 'checkbox') ->add('submit', 'submit'); } }
php artisan make:controller SongsController
app/Http/Controllers/SongsController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Kris\LaravelFormBuilder\FormBuilder; class SongsController extends Controller { public function create(FormBuilder $formBuilder, Request $request) { $form = $formBuilder->create('App\Forms\SongForm', [ 'method' => 'POST', 'url' => route('song'), ]); $req = $request->all(); return view('song', compact('form', 'req')); } }
GET/POST 共に受け取れるように設定
routes/web.php
Route::any('song','SongsController@create')->name('song');
resources/views/song.blade.php
<!-- resources/views/song.blade.php --> <!DOCTYPE HTML> <html> <head> <title>FormBuilder</title> </head> <body> <h1>FormBuilder TEST</h1> @section('content') {!! form($form) !!} @foreach ($req as $k => $v) <li>{{ $k .' : '.$v }}</li> @endforeach @endsection @yield('content') </body> </html>
Using version ^1.20 for kris/laravel-form-builder ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 2 installs, 0 updates, 0 removals - Installing laravelcollective/html (v5.8.0): Downloading (100%) - Installing kris/laravel-form-builder (1.20.0): Downloading (100%) Writing lock file Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi In MemcachedConnector.php line 69: Class 'Memcached' not found