I have a students table and fees table.
students
--------------
|id | name |
--------------
fees*
---------------------------------------------------------
| id| student_id | paid_fees | created_at | updated_at |
---------------------------------------------------------
Here, student_id from fees is foreign key that references to id on students.
I have two models for these tables, and I have defined a hasMany relationship between them. Because ,A student can submit the total fees in parts, So he can have more than one record in fees table
*Student.php
lass Student extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'roll_no', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
];
public function fees(){
return $this->hasMany('App\StudentFees');
}
}
Fee.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class StudentFees extends Model
{
public function student(){
return $this->belongsTo('App\Student');
}
}
I am trying to get paid_fee record which is related to a student_id with created_at or updated_at record too.
Maybe like this: [ [2500, '2019-05-19], [3500, '2019-06-28'] ]
So I am trying to get a list of all submitted fees along with date related to student_id.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire