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