在laravel 5中连接两个表

时间:2017-05-26 13:30:16

标签: php mysql laravel-5

我有两个表通过hasMany关系链接。一个是成员。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    protected $fillable = ['name', 'email'];

    public function schools()
    {
        return $this->hasMany(School::class);
    }
}

另一个是学校。

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class School extends Model
{
    protected $fillable = ['school'];

    public function member()
    {
        return $this->hasMany(Member::class);
    }
}

我想提交一个用户填写的表单但不幸的是,我收到以下错误。

 General error: 1364 Field 'member_id' doesn't have a default value (SQL: insert into `schools` (`school`, `updated_at`, `created_at`) values (Eton, 2017-05-26 13:28:50, 2017-05-26 13:28:50))

0 个答案:

没有答案