public static function addStar($id, $AccID) { GroupPagePostStar::create(['grouppagepostID' => $id, 'StudentID' => $AccID, 'groupstarstar' => 1]); }
public function starPost() { $in = Input::all(); $id = $in['id']; $AccID = $in['AccID']; $check = GroupPagePostStar::where('grouppagepostID', $id)->where('StudentID', $AccID)->orderBy('created_at', 'DESC')->first(); !count($check) ? GroupPagePostStar::addStar($id, $AccID) : GroupPagePostStar::updateStar($id, $AccID, $check->groupstarstar == 0 ? 1 : 0); $data = ['count' => GroupPagePostStar::where('grouppagepostID', $id)->where('groupstarstar', 1)->count(), 'isStar' => $check->groupstarstar == 0 ? 1 : 0]; return $data; }