Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rojonunoo's avatar

Struggling on how to solve this is issue in my laravel project

ok so am working on a school app. and am abit stuck now . Coding with laravel. now the problem is i have no idea how to go about these problems. so every Student has Fees , has Subjects , has a Grade or Class.

i have created my students model and the relationships with the grade, they work fine and fees too . But this is where the problem begins

  1. The school app needs to have 3 terms in a year so just the time frame , and in each term The students score will be inserted into their various profiles by the users i.e the teachers. now how do i go about setting the the terms cos in each them they might have different subjects and after the 3rd term they have to be promoted to the next class or Grade. i. I have no idea how i am going to promote the students to the next class. ii. i don't know how am going set the terms for each students cos fees may also vary depending on the terms.

I would glad and honestly accept and help at all.. Thanks so much for your time

0 likes
6 replies
SaeedPrez's avatar

You could simply achieve this by adding one or two columns to your table, because all you really need is a way to filter by the term and year.

So if you add the columns term and year you could do..

// Get the student
$student = Student::find(1);

// Get the 2nd term of 2017 with classes and grades
$terms = $student->terms()
    ->with(['classes', 'grades'])
    ->where('year', 2017)
    ->where('term', '2')
    ->first();

You could also query the Term model to get all students, classes and grades for a specific term.

$term = Term::with['students', 'classes', 'grades'])
    ->where('year', 2017)
    ->where('term', '3')
    ->first();
rojonunoo's avatar

@SaeedPrez ok ... but after each them the subjects results and the fees values will reset cos.. student fees might increase or decrease... subjects will differ also is would not always be 2017 it could 2020 .you understand i don't know if i am making sense .. and after the end of that terms i don't want to loose the student's previous data such as schools subjects score and all those you get it..

SaeedPrez's avatar

@rojonunoo

but after each them the subjects results and the fees values will reset cos..

You'll need to have results, classes, fees, etc in different tables. So when you add a new term, then you can add new classes with new fees to that term.

student fees might increase or decrease...

When you add a student to a class, you can save the current fee in the pivot table if you only want the fee to change for new students.

subjects will differ also is would not always be 2017 it could 2020

Of course, no problem.

and after the end of that terms i don't want to loose the student's previous data such as schools subjects score and all those you get it..

You shouldn't unless you change/deleted the data.

With all that said, I don't know much about your project, but I have a picture in my head what a project like yours should look like. It can be a bit complex with all the relationships and whatnot.

1 like
rojonunoo's avatar

@ SaeedPrez i see yea man it seems pretty complex i might just have to take it step by step .. thanks alot i see myself having a lot of questions is it possible fo r me to keep bothering you along the line if you don't mind pleaseee... you have already been of great help and i appreciate it honestly

rojonunoo's avatar

@ SaeedPrez so for the first part you saying i can't have my subjects and results to be in the same table . cos i was thinking i was only going to have a Subject tabe Schema:: subject_name and subject_score

but you saying i have a different table for score and subjects right?

SaeedPrez's avatar

@rojonunoo

is it possible fo r me to keep bothering you along the line if you don't mind

You're way better off if you just post your questions on this forum for a couple of reasons..

  • There are more knowledgeable people than me here
  • My schedule is very unpredictable, some days I won't have time at all so you'll get much faster response

so for the first part you saying i can't have my subjects and results to be in the same table . cos i was thinking i was only going to have a Subject tabe Schema:: subject_name and subject_score but you saying i have a different table for score and subjects right?

I would probably do it with many to many relationships and also save some extra data in the pivot tables. But like I mentioned earlier, it's a bit complicated on the relationship side and it can of course be done in different ways. So if you have an idea how to do it, then go for it.

Please or to participate in this conversation.