vendredi 26 mai 2017

linking two table in laravel 5

I have two tables which are linked via a hasMany relationship. One is for members.

<?php

 namespace App;

 use Illuminate\Database\Eloquent\Model;

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

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

The other one is for schools.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

 class School extends Model
{

 protected $fillable = ['school'];

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

}

I want to submit one form that the user fills in but unfortunately, I get the following error.

 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))

Any help would be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2s3lyhO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire