public function index() { if (Request::isMethod('get')) { /// if select filter if (Request::input('status')) { $status = Request::input('status'); if ($status == 'open') { $lists = Assignment::where('status', 1)->orderBy('id', 'desc')->paginate(50); } elseif ($status == 'closed') { $lists = Assignment::where('status', 0)->orderBy('id', 'desc')->paginate(50); } else { $lists = Assignment::orderBy('id', 'desc')->paginate(50); } } else { /// default - when load the page, only get Open $lists = Assignment::where('status', 1)->orderBy('id', 'desc')->paginate(50); } return view('admin.assignment.list', array('lists' => $lists)); } /// Ajax Delete $id = Request::input('data'); /// find user assignment applied this assignment $html_exist = '<ul>'; $e = array(); foreach ($id as $key => $value) { $ua = UserAssignment::where('assignment_id', $value)->count(); if ($ua) { $a = Assignment::find($value); $e[] = $value; $html_exist .= '<li>' . $a->customer_name . '</li>'; } } $html_exist .= '</ul>'; if (count($e)) { return array('error' => 'user_applied', 'name' => $html_exist); } Assignment::destroy($id); return array('error' => 'no', 'name' => ''); }
public function deleteAssignment($id) { return $this->assignment->destroy($id); }