I think so:
Add to your Student model:
public function invoices()
{
return $this->hasMany('App\Invoice');
}
and:
public function results()
{
return $this->hasMany('App\Result');
}
Inverse relations are: belongsTo
Yes @erdely I've done that already, I am guessing I am messing up on the tables somehow. Could you also tell me what does the 3 tables have it?
My current thing.
public function Invoices()
{
return $this->hasMany('App\Invoices');
}
public function results()
{
return $this->hasMany('App\Result');
}
And the table definitions
//The Invoices table
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id')->unsigned()->nullable()->index();
$table->string('name');
$table->string('student_roll');
$table->string('fees_paid');
$table->string('fees_remaining');
$table->string('fees_total');
$table->timestamps();
});
}
//The Students table
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('roll');
$table->string('address');
$table->string('school');
$table->string('city');
$table->string('class');
$table->string('email')->unique()->nullable();
$table->string('phone');
$table->timestamps();
});
}
//The results table
public function up()
{
Schema::create('results', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id')->unsigned()->nullable()->index();
$table->string('name');
$table->string('Physics');
$table->string('Maths');
$table->string('Chemistry');
$table->string('Biology');
$table->timestamps();
});
}
I want to have something like when I click "Student's roll number" I gets me back the related Invoices and related Results (can be many)
You have to define relations also in your migration: https://laravel.com/docs/5.3/migrations#foreign-key-constraints
Keep convenient table names and model names...
If you want to connect 2 tables in with third table then use pivot relationship or try: hasManyThrough
erdely said:
You have to define relations also in your migration: https://laravel.com/docs/5.3/migrations#foreign-key-constraints
Keep convenient table names and model names...
If you want to connect 2 tables in with third table then use pivot relationship or try: hasManyThrough
I showed you the relations in tables, i want to ask weather or not its correct.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community