HomeController.php
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace App\Http\Controllers;
use App\Models\Message;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
public function send_message(Request $request)
{
$user_id = Auth()->user()->id;
$message_params = [
'text' => $request->input('text'),
'reply_message_id' => $request->input('reply_message_id', null),
];
$new_message = Message::add_message(
$request,
$user_id,
$request->input('to_user_id'),
$message_params
);
$user_type = Auth()->user()->is_worker ? 'worker' : 'employer';
return response()->json([
'success' => true,
'url_redirect' => route($user_type . '.dialog', ['chat' => $new_message->chat_id_to])
]);
}
}