Creating Attendance system in laravel where need to check the classes for which attendance is submitted and which classes pending. Students data is saved in students table.
At the time of attendance the class whose attendance is submitted are saved in attendence_dates table. (To check which day for which class is working and data final submitted or not)
public function up()
{
Schema::create('attendence_dates', function (Blueprint $table) {
$table->bigIncrements('id');
$table->date('date')->default(date("Y-m-d"));
$table->string('clas_name', 20)->nullable();
$table->string('section_name',20)->nullable();
$table->boolean('working')->default(false);
$table->boolean('final')->default(false);
$table->string('remarks', 100)->nullable();
$table->unsignedBigInteger('updated_by')
->nullable();
$table->timestamp('updated_at')
->useCurrent()->useCurrentOnUpdate();
});
}
And the Attendances table where the attendance of students are saved with P AND A status.
public function up()
{
Schema::create('attendences', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('att_month')->default('0')->nullable();
$table->date('att_date')->useCurrent();
$table->string('clas_name', 20)->nullable();
$table->string('section_name',20)->nullable();
$table->unsignedBigInteger('student_id')->nullable();
$table->unsignedBigInteger('acc_id')->nullable();
$table->enum('status', ['P', 'A'])->default('P');
$table->foreign('student_id')->references('id')->on('students')
->onDelete('SET NULL')
->onUpdate('CASCADE'); // SET NULL, CASCADE, RESTRICT, DO NOTHING, NO ACTION
$table->foreign('acc_id')->references('acc_id')->on('students')
->onDelete('SET NULL')
->onUpdate('CASCADE');
$table->timestamps();
});
}
used this code to fetch all existing classes and sections from 'students' table.
$classAll = DB::table('students')
->select('clas_name', 'section_name')
->groupBy('clas_name','section_name')
->orderBy('clas_name','ASC')
->orderBy('section_name','ASC')
->get();
And this to fetch classes and sections whose attendance is submitted.
// FETCH POSTED CLASSES DATA
$posted = DB::table('attendence_dates')
->select('clas_name', 'section_name')
->where('date', $date)
->groupBy('clas_name','section_name')
->orderBy('clas_name','ASC')
->orderBy('section_name','ASC')
->get();
Now have to show the pending classes i.e. classes which not submitted.
I am learning laravel, from search and documentation i got this collection function.
tried $pending = $classAll->diff($posted); but its giving error "Object of class stdClass could not be converted to string ".
Also tried $pending = $classAll->diffKeys($posted);
its not giving any error, but not getting desired results. Total count is reduced but not exact classes removed from total.
I want to get the classes and sections which attendance not submitted on particular date. If there is any function available in laravel or query to get the desired result.