Form layout

Multi-column layout (column)

Form layout - 图1

Similar to the above diagram of the left and right two-column layout, you can refer to the following code to achieve the following

  1. // The first column takes up 1/2 of the page width.
  2. $form->column(6, function (Form $form) {
  3. $form->text('name')->required();
  4. $form->date('born')->required();
  5. $form->select('education')->options([...])->required();
  6. $form->text('nation')->required();
  7. $form->text('native')->required();
  8. $form->text('job')->required();
  9. $form->text('code')->required();
  10. $form->text('phone')->required();
  11. $form->text('work')->required();
  12. $form->text('census')->required();
  13. });
  14. // The second column takes up 1/2 of the page width.
  15. $form->column(6, function (Form $form) {
  16. $form->image('avatar');
  17. $form->decimal('wages');
  18. $form->decimal('fund');
  19. $form->decimal('pension');
  20. $form->decimal('fee');
  21. $form->decimal('business');
  22. $form->decimal('other');
  23. $form->text('area')->default(0);
  24. $form->textarea('illness');
  25. $form->textarea('comment');
  26. });
  27. // Adjust the width of all forms.
  28. $form->width(9, 2);

The above layout features use the bootstrap grid layout system, the sum of the width of all columns must not exceed 12, and also supports the use of hasMany and array forms.

  1. $form->hasMany('jobs', function ($form) {
  2. $form->column(6, function (Form $form) {
  3. $form->text('name')->required();
  4. $form->date('born')->required();
  5. });
  6. $form->column(6, function (Form $form) {
  7. $form->image('avatar');
  8. $form->decimal('wages');
  9. });
  10. });

Multi-row layout (row)

use

  1. $form->row(function (Form\Row $form) {
  2. $form->width(4)->text('username')->required();
  3. $form->width(3)->text('title');
  4. ...
  5. });
  6. $form->row(function (Form\Row $form) {
  7. ...
  8. });
  9. ...

result Form layout - 图2

It is also supported in hasMany and array forms.

  1. $form->hasMany('jobs', function ($form) {
  2. $form->row(function (Form\Row $form) {
  3. ...
  4. });
  5. $form->row(function (Form\Row $form) {
  6. ...
  7. });
  8. });

Tab form (tab)

If the form has too many elements, the form page will be too long, in this case you can use the tab method to separate the form:

  1. $form->tab('Basic info', function (Form $form) {
  2. $form->text('username');
  3. $form->email('email');
  4. })->tab('Profile', function (Form $form) {
  5. $form->image('avatar');
  6. $form->text('address');
  7. $form->mobile('phone');
  8. })->tab('Jobs', function (Form $form) {
  9. $form->hasMany('jobs', function ($form) {
  10. $form->text('company');
  11. $form->date('start_date');
  12. $form->date('end_date');
  13. });
  14. });

The tab layout also allows nested use of column and row layouts.

  1. $form->tab('Basic info', function (Form $form) {
  2. $form->column(6, function (Form\BlockForm $form) {
  3. $form->display('id');
  4. $form->text('name');
  5. });
  6. $form->column(6, function (Form\BlockForm $form) {
  7. $form->text('username');
  8. });
  9. })

Set the default display of Tab

  1. // Show the Tab with the title Title 2 by default
  2. $form->getTab()->active('Title2');
  3. // You can also specify an offset
  4. $form->getTab()->activeByIndex(1);
  5. $form->tab('Heading 1', function ($form) {
  6. ...
  7. });
  8. $form->tab('Title2', function ($form) {
  9. ...
  10. });

Fieldset Layout

  1. $form->fieldset('分组', function (Form $form) {
  2. $form->text('company');
  3. $form->date('start_date');
  4. $form->date('end_date');
  5. });

If you want to hide by default

  1. $form->fieldset('分组', function (Form $form) {
  2. ...
  3. })->collapsed();

result

Form layout - 图3

Block layout (block)

If your form has a lot of fields, you can block your form and allow nested column and row layouts by doing the following

  1. $form->block(8, function (Form\BlockForm $form) {
  2. // Set the title
  3. $form->title('Basic settings');
  4. // Show bottom submit button
  5. $form->showFooter();
  6. // Set the field width
  7. $form->width(9, 2);
  8. $form->column(6, function (Form\BlockForm $form) {
  9. $form->display('id');
  10. $form->text('name');
  11. $form->email('email');
  12. $form->image('avatar');
  13. $form->password('password');
  14. });
  15. $form->column(6, function (Form\BlockForm $form) {
  16. $form->text('username');
  17. $form->email('mobile');
  18. $form->textarea('description');
  19. });
  20. });
  21. $form->block(4, function (Form\BlockForm $form) {
  22. $form->title('Block 2');
  23. $form->text('nickname');
  24. $form->number('age');
  25. $form->radio('status')->options(['1' => 'default', 2 => 'freeze'])->default(1);
  26. $form->next(function (Form\BlockForm $form) {
  27. $form->title('Block 3');
  28. $form->date('birthday');
  29. $form->date('created_at');
  30. });
  31. });

result Form layout - 图4