You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone, I am the self-learned Laravel from Vietnam
I have 3 tables like this
Student
id
name
class Student extends Model
{
protected$table = 'students';
publicfunctionmarks () {
return$this->belongsToMany( 'App\Models\Subject', 'marks' )->using( 'App\Models\Mark');
}
}
Subject
id
name
class Subject extends Model
{
protected$table = 'subjects';
publicfunctionmarks () {
return$this->belongsToMany( 'App\Models\Student', 'marks' )->using( 'App\Models\Mark');
}
}
Mark
subject_id
student_id
type_of_exam
times_taking_exam
mark
class Mark extends Pivot
{
protected$table = 'marks';
publicfunctionstudent() {
return$this->belongsTo('App\Models\Student','student_id');
}
publicfunctionsubject() {
return$this->belongsTo('App\Models\Student','subject_id');
}
public$timestamps = false;
}
The table Mark which has 4 column primary key (id_subject, id_student, type_of_exam, times_taking_exam)
I don't know my design database is correct or not, but if it did, how can I use sync to update or insert mark for my student.
Because I understand that the method sync is like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone, I am the self-learned Laravel from Vietnam
I have 3 tables like this
Student
Subject
Mark
The table Mark which has 4 column primary key (id_subject, id_student, type_of_exam, times_taking_exam)
I don't know my design database is correct or not, but if it did, how can I use sync to update or insert mark for my student.
Because I understand that the method sync is like this:
But it is not correct for this situation cause it will run this code like this:
Instead, I want this:
I have tried use Mark as Model but I think it's not the best way.
Beta Was this translation helpful? Give feedback.
All reactions