I have the following function:
public function addSubject(Request $request) {
$student=User::find($request->invisible);
$classsubjects = $request['classsubjects'];
$student->classSubjects()->attach($cclasssubjects);
}
This gives me an error saying:
BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::attach()
The function classSubjects() in your Package model has to return a BelongsToMany relationship in order to use attach().
public function classSubjects() {
return $this->belongsToMany('classSubjects');
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments