2014-12-15 4 views
0

Я хочу вставить строку в свою базу данных, используя ввод формы.eloquent create not inserting all

// PersonController

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

// класс Person

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; 
} 

// Форма в View

{{ Form::open(array('action' => '[email protected]')) }} 
{{ 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() }} 

SQL-оператор, порожденный

$this->person->create($input) 

отсутствует внешний ключ (GROUP_ID) и логическое значение (isresponsible)

ответ

0

Это потому, что имена в вашей форме не совпадают имена атрибутов в базе данных.

isResponsible ≠ isresponsible 

group ≠ group_id 

Просто измените имена в форму:

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