Ejemplo n.º 1
0
 /**
  * Bug list:
  * Chat wont automatically update if it is the first message
  *
  * Improvements:
  * Update the time for all messages repeatedly
  */
 public function create(Request $request)
 {
     $this->validate($request, ['body' => 'required|max:200']);
     do {
         $key = str_random(32);
         $chat_key = Chat::where('key', $key)->first();
     } while (!empty($chat_key));
     if (!Auth::check()) {
         return $response->json(json_encode(['auth' => false]));
     }
     Chat::create(['body' => $request->input('body'), 'user_id' => Auth::user()->id, 'key' => $key]);
     return;
 }