Thursday, February 1, 2018

many-to-many relationship – save data - development

many-to-many relationship – save data

I made relationship between Film and Performer model.
Into Films model:

  public function Performers(){
    return $this->belongsToMany('AppPerformer');
  }

Into Performer model

public function Films(){
  return $this->belongsToMany('AppFilms');
}

I created table films_performer and relationship works, if I would add data manually. I hove w problem with save data into film_performer after send form. Into controller I attach it.

$film->performers()->attach($request->performers);

I don’t have any errors. I used dd($request to check array performers and everything is ok)larave



from Laravel Questions and Answers https://laravelquestions.com/php/many-to-many-relationship-save-data/
via Lzo Media

No comments:

Post a Comment