Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将值插入laravel 5.1中的数据库_Laravel_Laravel 5.1 - Fatal编程技术网

无法将值插入laravel 5.1中的数据库

无法将值插入laravel 5.1中的数据库,laravel,laravel-5.1,Laravel,Laravel 5.1,我有这个问题,当我从表单输入返回所有值时,它会返回所有已填写的值。但是,当我在控制器的store方法下持久化到数据库中时,它会插入空值。有人能帮我吗?非常感谢。下面是我的代码 public function store(EnrollmentRequest $request) { return $request->all(); return redirect('/enrollment/create'); } 正如您在顶部看到的,它返回所有输入。但是,当我在数据库中持久

我有这个问题,当我从表单输入返回所有值时,它会返回所有已填写的值。但是,当我在控制器的store方法下持久化到数据库中时,它会插入空值。有人能帮我吗?非常感谢。下面是我的代码

public function store(EnrollmentRequest $request)
{   
    return $request->all();
    return redirect('/enrollment/create');
}
正如您在顶部看到的,它返回所有输入。但是,当我在数据库中持久化它时,它只返回id和时间戳

public function store(EnrollmentRequest $request)
{   
    $enrollment = Enrollment::create([$request->all()]);
    return $enrollment;  return redirect('/enrollment/create');
}
这是我的报名表:

    Schema::create('enrollments', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('student_id');
        $table->string('subject_description');
        $table->string('subject_code');
        $table->time('schedule');
        $table->string('room_no');
        $table->integer('no_of_units');
        $table->string('section');
        $table->timestamps();
    });
还有我的主题表:

Schema::create('subjects', function (Blueprint $table) {
        $table->increments('id');
        $table->string('subject_code');
        $table->string('subject_description');
        $table->time('schedule');
        $table->string('room_no');
        $table->integer('no_of_units');
        $table->timestamps();
    });
非常感谢你的帮助

   protected $table = 'enrollments';

protected $fillable = [
    'subject_code',
    'subject_description',
    'section',
    'schedule',
    'room_no',
    'no_of_units'
];

听上去,您还没有更新注册模型的
$filleble
属性

因此,您在批量分配中遇到了麻烦,只有默认情况下可填充的值(ID和时间戳)被插入,其余的被忽略

您需要添加到
$filleble
属性中,以便它包含希望通过批量分配(即运行
Enrollment::create([$request->all()]);
时作为可填充字段的其他字段

它应该如下所示:

protected $fillable = ['student_id', 'subject_description', 'subject_code', 'schedule', 'room_no', 'no_of_units', 'section'];

你能给我们展示一下表格的模型吗?你能用$enrollment=enrollment::create($request->all())试试吗;在所有字段或任何特定字段上插入空值?是否在模型中初始化了
protected$filleble
注册?@James I更新上述信息。请检查包含的注册模型也谢谢,但我已经解决了,Minhajul的答案是正确的。