push
Mar 27, 2017
8
Level 13
Have anyone using redis as database for particular table?
I try to implement attendance system in my app so attendance will taken by teacher daily so its lots of data so think redis is better choice but how to use redish for this operation I don't know any one have idea please share here in my controller which I want to use redis here is my controller
public function student_take_attendence_post(Request $r)
{
$this->validate($r,[
'date' => 'required|date_format:d/m/Y',
'marked' => 'required',
]);
$user = Auth::user();
$students = Student::whereHas('studentacadmic.courses.teacheracadmic',
function($q) use($user){
$q->where('teacher_id', $user->id);
})->whereHas('studentacadmic', function($q) use($user){
$q->where('section_id',$user->teacheracadmic->section_id);
})->latest()->get();
$d = $r->date;
$dates = str_replace('/', '-', $d);
$date = date('Y-m-d', strtotime($dates));
foreach ($students as $key => $value) {
$ids = $value->id;
//dd($ids);
$todayattendence = StudentAttendence::
where('student_id', $ids)
->whereDate('date' , $date)->first();
}
//dd($todayattendence);
if ($todayattendence) {
flash('You already marked attendence for date of '. $d );
return back();
} else{
foreach ($students as $key => $value)
{
$data = [
'date' => $r->date,
'marked' => $r->marked [$key],
'taker_id' => $user->id
];
$value->studentattendence()->create($data);
}
$studentss = Student::whereHas('studentattendence',function($q) use($date){
$q->whereDate('date',$date)
->where('marked',0);
})->select('emer_no','name')->get()->toArray();
$numbers = array_pluck($studentss, 'emer_no');
if ($studentss) {
event(new StudentAbsent($numbers,$d));
}
flash()->success('Successfully attendence marked');
return back();
}
}
my students_attendences table
Schema::create('student_attendences', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id')->unsigned()->index();
$table->integer('taker_id')->unsigned()->index();
$table->date('date');
$table->boolean('marked');
$table->timestamps();
})
Please or to participate in this conversation.