/** * Update the donner dashboard * fetch new requests from db * responds to post request on /update-donner-dashboard route */ public function updateDashboard(Request $request) { $count = 0; $mainCount = 0; //first check if the cookie is set or not //this code will run when the count cookie is set if (Cookie::get('count')) { //fetch only difference records(new records) $count = Problem::count(); //check if new rows have been added to the table then send the new reply //else no need to send data if (Cookie::get('count') != $count) { //if user entered a new form if ($count > Cookie::get('count')) { $mainCount = $count - Cookie::get('count'); $problems = Problem::orderBy('id', 'desc')->take($mainCount)->get(); $response = new Response($problems); $response->withCookie(cookie()->forever('count', $count)); return $response; } if ($count < Cookie::get('count')) { $response = new Response("No New Problems"); return $response; } //$mainCount = max($count , Cookie::get('count')) - min($count , Cookie::get('count')); //setcookie("mainCount", $mainCount); //setcookie("1", "cookie was set but counts were not equal"); } else { $response = new Response("No New Problems"); return $response; } } else { //fetch all records //this code will run first time when count cookie is not set $problems = Problem::orderBy('id', 'desc')->get(); $count = $problems->count(); //this cookie will expire in next 5 years $response = new Response($problems); $response->withCookie(cookie()->forever('count', $count)); return $response; } }
public function showProblems() { $problemas = Problem::orderBy('id', 'asc')->paginate(5); return view('admin/problemas', ['problemas' => $problemas]); }