简体   繁体   English

Laravel-来自表单的变量未保存在create方法中

[英]Laravel - variable from form not being saved in create method

I am trying to save the information from a form, into the database. 我正在尝试将信息从表单保存到数据库中。 I can successfully save all fields minus one - a select field. 我可以成功保存所有字段减一个-选择字段。

Form HTML (blade): 表单HTML(刀片):

{!! Form::select('ClinicTypes', $clinicTypes, null, ['class' => 'form-control',
       'name' => 'speciality']) !!}

That displays in HTML: 以HTML显示:

<select class="form-control" name="speciality">
    <option value="1"></option>
    <option value="2"></option>
</select>

If I: dd($request->get('speciality')); 如果我: dd($request->get('speciality')); it returns '1', which is correct, however, when I add this into the create function, it saves in the database as 0. 它返回“ 1”,这是正确的,但是,当我将其添加到create函数中时,它将在数据库中另存为0。

Snippet from create method: 创建方法的代码段:

'clinic_types_id' => $request->get('speciality'),

dd屏幕截图

Snippet from database: 数据库片段:

数据库

Schema: 架构:

Schema::create('clinics', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('user_id');
            $table->integer('clinic_types_id');

Why is it saving as 0, instead of 1? 为什么将其另存为0,而不是1? Any help would be hugely appreciated. 任何帮助将不胜感激。 Many thanks. 非常感谢。

You might make sure it's in the $fillable array for the model. 您可能会确保它在模型的$fillable数组中。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Clinic extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['clinic_types_id'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM