in my database I am trying to save my data into database, table fish, but only my bear_id is being saved and not the fish_location or fish_type. Can anyone help?
Information: one bear have many fish (one to many relationship)
Contoller:
public function submit(Request $request)
{
$bear= Session::get('data');
$test = array();
$test['fish_location'] = $request->fish_location;
$test['fish_type'] = $request->fish_type;
$fish = new fish;
$fish = fish::create([$test]);
$fish->bears()->associate($bear);
$fish->save();
return ('thank you');
}
fish model:
class fish extends Eloquent
{
protected $fillable = array('fish_type', 'fish_location', 'bear_id');
public function bears() {
return $this->belongsTo('App\bear');
}
fish table:
Schema::create('fishs', function (Blueprint $table) {
$table->increments('id');
$table->engine = 'InnoDB';
$table->string('fish_location');
$table->string('fish_type');
$table->integer('bear_id');
$table->timestamps();
});