Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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 雄辩的创造,而不是插入一切_Laravel_Eloquent - Fatal编程技术网

Laravel 雄辩的创造,而不是插入一切

Laravel 雄辩的创造,而不是插入一切,laravel,eloquent,Laravel,Eloquent,我想使用表单中的输入在数据库中插入一行 //个人控制器 Public function store(){ $input = Input::all(); if(! $this->person->fill($input)->isValid()){ return Redirect::back()->withInput()->withErrors($this->person->messages); } $this

我想使用表单中的输入在数据库中插入一行

//个人控制器

Public function store(){ 
    $input = Input::all();
    if(! $this->person->fill($input)->isValid()){
        return Redirect::back()->withInput()->withErrors($this->person->messages);
    }
    $this->person->create($input);
}
//班主任

protected $fillable = ['name', 'group_id', 'email', 'phone', 'address', 'isresponsible'];
public $messages;
public function isValid(){
    $validation = Validator::make($this->attributes, static::$rules);
    if ($validation->passes()) return true;
    $this->messages = $validation->messages();
    return false;
}
//视野中的形式

{{ Form::open(array('action' => 'PersonController@store')) }}
{{ Form::text('name') }}
{{$errors->first('name', '<span class=error>:message</span>')}}
{{ Form::select('group', $groups, Input::old('id')) }}
{{ Form::email('email') }}
{{ Form::text('phone') }}
{{ Form::text('address') }}
{{ Form::checkbox('isResponsible') }}
{{ Form::submit('Create') }}
{{ Form::close() }}
缺少外键组id,且布尔值为Responsible

,这是因为表单中的名称与数据库中属性的名称不匹配

isResponsible ≠ isresponsible

group ≠ group_id
只需更改表单中的名称:

{{ Form::select('group_id', $groups, Input::old('group_id')) }}
{{-- ... --}}
{{ Form::checkbox('isresponsible') }}
{{ Form::select('group_id', $groups, Input::old('group_id')) }}
{{-- ... --}}
{{ Form::checkbox('isresponsible') }}