From b1c501e2f239ef6dcbf5e55e403834d793c6a0f6 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 30 Jun 2018 23:44:50 +0200 Subject: Finished websocket integration --- app/Http/Controllers/Auth/LoginController.php | 2 +- app/Http/Controllers/Auth/RegisterController.php | 2 +- .../Controllers/Auth/ResetPasswordController.php | 4 +- app/Http/Controllers/SocketController.php | 44 ++++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/SocketController.php (limited to 'app/Http') diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b2ea669..191b2b6 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -25,7 +25,7 @@ class LoginController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index e749c07..be65e85 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -28,7 +28,7 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index cf726ee..f5edc22 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -16,7 +16,7 @@ class ResetPasswordController extends Controller | and uses a simple trait to include this behavior. You're free to | explore this trait and override any methods you wish to tweak. | - */ + */ use ResetsPasswords; @@ -25,7 +25,7 @@ class ResetPasswordController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/SocketController.php b/app/Http/Controllers/SocketController.php new file mode 100644 index 0000000..dc49fcf --- /dev/null +++ b/app/Http/Controllers/SocketController.php @@ -0,0 +1,44 @@ +on('messages.user_id', '=', 'users.id'); + })->select( + 'users.name', 'messages.message')->orderBy('messages.created_at') + ->get(); + + return view('writeMessage', compact('messages')); + } + + //Send Message + public function sendMessage(Request $request) + { + $user = Auth::user(); + + $input = $request->all(); + $redis = LRedis::connection(); + + if (!isset($input['message']) || trim($input['message']) === '') { + } else { + Message::create([ + 'user_id' => $user->id, + 'message' => $input['message'], + ]); + + $data = ['message' => $input['message'], 'user' => $user->name]; + $redis->publish('message', json_encode($data)); + } + } +} -- cgit v1.2.3