public function forumId($id) { if (Topic::where('id', '=', $id)->count() > 0) { $topic = Topic::find($id); $topic->view = $topic->view + 1; $topic->save(); if (Commit::where('topic_id', '=', $id)->count() > 0) { $commit = Commit::where('topic_id', '=', $id)->get(); } else { $commit = array("無留言"); } $writer = Student::find($topic->stu_id); $export[] = array("title" => urlencode(str_replace("\\'", "'", addslashes($topic->title))), "writer" => urlencode(str_replace("\\'", "'", addslashes($writer->nick))), "body" => urlencode(str_replace("\\'", "'", base64_encode($topic->body))), "file" => urlencode(str_replace("\\'", "'", addslashes($topic->file))), "date" => $topic->day, "view" => $topic->view); if ($commit[0] != "無留言") { for ($i = 0; $i < count($commit); $i++) { $export[] = array("title" => "", "writer" => urlencode(str_replace("\\'", "'", addslashes(Student::find($commit[$i]->stu_id)->nick))), "body" => urlencode(str_replace("\\'", "'", base64_encode($commit[$i]->body))), "file" => " ", "date" => $commit[$i]->day); } } } else { $export[] = array("title" => " ", "writer" => " ", "body" => " ", "file" => " ", "day" => " "); } return urldecode(json_encode($export)); }