【发布时间】:2014-08-10 01:18:41
【问题描述】:
我是 laravel 新手:所以我有 2 张桌子:
- 用户
- 帐户
每次用户登录时,他们都可以创建帐户并将信息放在页面中。 我得到了table:
public function up() {
Schema::create('users', function($table) {
$table->increments('id');
$table->string('email')->unique();
$table->boolean('remember_token');
$table->string('password');
$table->timestamps();
});
和
Schema::create('accounts', function($table) {
# AI, PK
$table->increments('id');
# created_at, updated_at columns
$table->timestamps();
# General data...
$table->integer('user_id')->unsigned();
$table->string('name_first');
$table->string('name_last');
$table->date('dob');
$table->string('address');
$table->string('phone');
$table->string('email')->unique();
$table->string('event');
# Define foreign keys...
$table->foreign('user_id')
->references('id')
->on('users');
});
然后我对 create.blade.php 表单信息有我的看法:
{{ Form::open(array('url' => 'accounts')) }}
<div class="form-group">
{{ Form::label('name_first', 'Frist Name') }}
{{ Form::text('name_first', Input::old('name_first'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('name_last', 'Last Name') }}
{{ Form::text('name_last', Input::old('name_last'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('dob', 'DOB') }}
{{ Form::text('dob', Input::old('dob'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('phone', 'Phone Number') }}
{{ Form::text('phone', Input::old('phone'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('address', 'Mailing Address') }}
{{ Form::text('address', Input::old('address'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::email('email', Input::old('email'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('event', 'Party/Event') }}
{{ Form::select('event', array('0' => 'Birthday', '1' => 'Baby Shower', '2' => 'Wedding', '3' => 'Anniversary'), Input::old('party'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Adding RSVP now!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
我正在尝试从表单中获取所有值的视图:以及从我的用户表中查看的电子邮件...但我一直在下面收到此错误:我从哪里开始。推荐会很可爱,谢谢
Illuminate \ Database \ QueryException (23000)
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`authapp`.`accounts`, CONSTRAINT `accounts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)) (SQL: insert into `accounts` (`name_first`, `name_last`, `dob`, `address`, `phone`, `email`, `event`, `updated_at`, `created_at`) values (jea, las, 21, ;lsdkfj, ;fd, iamjeannie@gmail.com, 3, 2014-08-10 01:14:07, 2014-08-10 01:14:07))
【问题讨论】: