Ejemplo n.º 1
0
 public function send(Request $request)
 {
     if ($request->session()->has('uid') == false) {
         return response()->json(['error' => 'Access denied'], 403, ['Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Credentials' => 'true']);
     }
     $message = $request->get('message');
     $user = User::where('id', $request->session()->get('uid'))->first();
     $user->last_seen = Carbon::now()->toDateTimeString();
     $user->save();
     $message = LinkFinder::replace($message);
     if (!$user) {
         exit;
     }
     $nickname = $user->nickname;
     if ($nickname == null) {
         header('Access-Control-Allow-Origin: *');
         header('Access-Control-Allow-Credentials: true');
         die('error');
     }
     if ($nickname != null && $message != null) {
         $messages = new Messages();
         $messages->user_id = $user->id;
         $messages->message = $message;
         Cache::put($nickname, $nickname, 10);
         header('Access-Control-Allow-Origin: *');
         header('Access-Control-Allow-Credentials: true');
         header('Content-Type: application/json');
         echo json_encode(['success' => $messages->save(), 'message' => $messages->message]);
         exit;
     }
     return response()->json(['success' => false])->header('Access-Control-Allow-Origin', '*');
 }
Ejemplo n.º 2
0
 public function send(Request $request)
 {
     $message = $request->get('message');
     if ($message != null && strlen(trim($message)) > 0) {
         $m = new Messages();
         $m->user_id = $this->user->id;
         $m->message = $message;
         return response()->json(['success' => boolval($m->save())]);
     }
     $this->user->last_seen = Carbon::now()->toDateTimeString();
     $this->user->save();
     return response()->json(['error' => 'Empty message']);
 }