php - 如何使用 Laravel 将带有 yes no 复选框的表设置为 mysql
问题描述
请帮我解决这个问题:使用 Laravel
- 功能/目的:
访客(无注册/登录) - 完成 <有登录/注册 - 工作>
- 客观的:
带有基本文本字段的调查表:fname、lname、ID 号、移动电话,然后是 3 个带有复选框的yes
问题。no
- 我的挑战:我不知道如何将 2options 调查问题迁移到数据库?
嗨这是我的迁移 create_survey_posts_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSurveyPostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('fname');
$table->string('lname');
$table->string('id_number');
$table->string('mobile');
$table->string('sq-symptoms');
$table->string('sq-travel');
$table->string('sq-contact');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('survey_posts');
}
}
我应该使用什么,sq-symptoms
因为它是一个单选按钮yes
和no
上传(迁移)到 mysql 的选项
解决方案
带有验证的无线电输入可能吗?
<fieldset>
<legend>Symptoms</legend>
<label>Yes<input type="radio" name="sq_symptoms" value="Yes"></label>
<label>No<input type="radio" name="sq_symptoms" value="No"></label>
</fieldset>
// laravel validation
sq_symptoms: ['required', 'in:Yes,No']
// using the Rule facade
sq_symptoms: ['required', Rule::in(['Yes', 'No'])]
此示例中不需要for
或id
属性。为了解释原因,这里是MDN 关于<label>
元素的文档的摘录:
要将
<label>
与<input>
元素相关联,您需要提供<input>
anid
属性。然后<label>
需要一个for
属性,其值与输入的 相同id
。或者,您可以将
<input>
直接嵌套在 中<label>
,在这种情况下,不需要for
and属性,因为关联是隐式的:id
推荐阅读
- django - Django 如何根据输入或状态重用 URL 和视图?
- r - 如何在 R 中使用正则表达式检测和删除缩写?
- python-3.x - 如何将内存视图映射到已知结构?
- php - Amazon EC2 :- 无法将 PHP 版本从 7.4 降级到 7.2
- java - Maven更新问题
- javascript - 使用 JavaScript 在图像上放置生成的条形码
- git - 无业游民机器上的 SSH 密钥问题和 Mac 上的 Github
- c# - Microsoft.AspNetCore.Mvc.Razor.RazorPage
.Model.get 返回 null - regex - 正则表达式搜索子字符串
- python-3.x - Python中的搜索优化