From 64e081e4c0947571954bfa3787a075617283fb67 Mon Sep 17 00:00:00 2001 From: sousuke-code <162286022+sousuke-code@users.noreply.github.com> Date: Sat, 22 Jun 2024 23:29:12 +0900 Subject: [PATCH 01/53] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=83=E3=83=88?= =?UTF-8?q?=EF=BC=88=E4=BC=81=E6=A5=AD=E3=81=A8=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=EF=BC=89=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 78 ++++++--- app/Models/Chat.php | 19 +- ...024_06_21_052736_create_messages_table.php | 33 ---- ... 2024_06_22_054146_create_chats_table.php} | 6 + resources/views/chats/index.blade.php | 16 -- resources/views/chats/show.blade.php | 20 --- resources/views/company-chat-page.blade.php | 165 ++++++++++++++++++ resources/views/layout/app.blade.php | 2 + resources/views/user-chat-page.blade.php | 160 +++++++++++++++++ resources/views/users/github.blade.php | 8 +- routes/web.php | 17 +- 11 files changed, 410 insertions(+), 114 deletions(-) delete mode 100644 database/migrations/2024_06_21_052736_create_messages_table.php rename database/migrations/{2024_06_21_052719_create_chats_table.php => 2024_06_22_054146_create_chats_table.php} (85%) delete mode 100644 resources/views/chats/index.blade.php delete mode 100644 resources/views/chats/show.blade.php create mode 100644 resources/views/company-chat-page.blade.php create mode 100644 resources/views/user-chat-page.blade.php diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 2e190e8..06611ea 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -4,37 +4,71 @@ use Illuminate\Http\Request; use App\Models\Chat; -use App\Models\Message; use Illuminate\Support\Facades\Auth; class ChatController extends Controller { - public function index() - { - if (Auth::guard('web')->check()) { - $chats = Chat::where('user_id', Auth::id())->get(); - } else if (Auth::guard('company')->check()){ - $chats = Chat::where('company_id', Auth::id())->get(); - } - return view('chats.index', compact('chats')); + + public function loadUserChats(){ + $userId = Auth::id(); + $companyId = 1; + + $chats = Chat::where('user_id', $userId) + ->where('company_id', $companyId) + ->get(); + return view('user-chat-page', compact('chats', 'companyId', 'userId')); + } - public function show(Chat $chat) + + public function Userstore(Request $request) { - $messages = $chat->messages()->get(); - return view('chats.show', compact('chat', 'messages')); + $validatedData = $request->validate([ + 'message' => 'required|string|max:255', + 'company_id' => 'required|integer', + ]); + + $message = Chat::create([ + 'message' => $validatedData['message'], + 'user_id' => Auth::id(), + 'company_id' => $validatedData['company_id'], + 'sender_type' => 'user', + 'receiver_type' => 'company', + ]); + + return response()->json(['status' => 'メッセージが正常に保存されました!']); + } + + + public function loadCompanyChats(){ + $userId = 1; + $companyId = Auth::guard('company')->id(); + + $chats = Chat::where('user_id', $userId) + ->where('company_id', $companyId) + ->get(); + return view('company-chat-page', compact('chats', 'userId', 'companyId')); } - public function storeMessage(Request $request, Chat $chat) + + public function Companystore(Request $request) { - $message = new Message(); - $message->chat_id = $chat->id; - $message->sender_id = Auth::id(); - $message->sender_type = Auth::guard('web')->check() ? 'user': 'company'; - $message->message = $request->message; - $message->save(); - - return redirect()->route('chat.show', $chat); - } + $validatedData = $request->validate([ + 'message' => 'required|string|max:255', + 'user_id' => 'required|integer', + '' + ]); + + $message = Chat::create([ + 'message' => $validatedData['message'], + 'user_id' => $validatedData['user_id'], + 'company_id' =>Auth::guard('company')->id(), + 'sender_type' => 'company', + 'receiver_type' => 'user', + ]); + + return response()->json(['status' => 'メッセージが正常に保存されました!']); + } + } diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 17b5d46..d888deb 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -10,22 +10,11 @@ class Chat extends Model use HasFactory; protected $fillable = [ + 'sender', + 'message', 'user_id', 'company_id', + 'sender_type', + 'receiver_type', ]; - - public function user() - { - return $this->belongsTo(User::class); - } - - public function company() - { - return $this->belongsTo(Company::class); - } - - public function messages() - { - return $this->hasMany(Message::class); - } } diff --git a/database/migrations/2024_06_21_052736_create_messages_table.php b/database/migrations/2024_06_21_052736_create_messages_table.php deleted file mode 100644 index 5e2d187..0000000 --- a/database/migrations/2024_06_21_052736_create_messages_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->unsignedBigInteger('chat_id'); - $table->unsignedBigInteger('sender_id'); - $table->enum('sender_type', ['user', 'company']); - $table->text('message'); - $table->timestamps(); - - $table->foreign('chat_id')->references('id')->on('chats')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('messages'); - } -}; diff --git a/database/migrations/2024_06_21_052719_create_chats_table.php b/database/migrations/2024_06_22_054146_create_chats_table.php similarity index 85% rename from database/migrations/2024_06_21_052719_create_chats_table.php rename to database/migrations/2024_06_22_054146_create_chats_table.php index bc48cb7..02b6bef 100644 --- a/database/migrations/2024_06_21_052719_create_chats_table.php +++ b/database/migrations/2024_06_22_054146_create_chats_table.php @@ -15,11 +15,17 @@ public function up(): void $table->id(); $table->unsignedBigInteger('user_id'); $table->unsignedBigInteger('company_id'); + $table->text('message'); + $table->string('sender_type'); + $table->string('receiver_type'); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); }); + + } /** diff --git a/resources/views/chats/index.blade.php b/resources/views/chats/index.blade.php deleted file mode 100644 index 4abd241..0000000 --- a/resources/views/chats/index.blade.php +++ /dev/null @@ -1,16 +0,0 @@ -@extends('layout.app') - -@section('content') -
{{ $chat['message'] }}
+{{ $chat['message'] }}
+{{ $chat['message'] }}
+{{ $chat['message'] }}
+該当するユーザーが見つかりませんでした。
++ {{ $user->name }} +
++ {{ $user->email }} +
+該当するユーザーが見つかりませんでした。
@else @@ -17,6 +66,7 @@ @endforeach - @endif - - \ No newline at end of file + @endif --}} + + +@endsection \ No newline at end of file From 728572c44953f620c71678bff1e11e3e857d4110 Mon Sep 17 00:00:00 2001 From: sousuke-code <162286022+sousuke-code@users.noreply.github.com> Date: Sun, 23 Jun 2024 00:44:06 +0900 Subject: [PATCH 03/53] =?UTF-8?q?=E4=BC=81=E6=A5=AD=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=81=B8=E3=81=AE=E9=81=B7=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/company/profile.blade.php | 2 +- resources/views/layout/app.blade.php | 2 +- routes/web.php | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/resources/views/company/profile.blade.php b/resources/views/company/profile.blade.php index b9eeaa9..3ef51eb 100644 --- a/resources/views/company/profile.blade.php +++ b/resources/views/company/profile.blade.php @@ -8,7 +8,7 @@マイページ編集
diff --git a/resources/views/layout/app.blade.php b/resources/views/layout/app.blade.php index 7ddbd96..d1cd579 100644 --- a/resources/views/layout/app.blade.php +++ b/resources/views/layout/app.blade.php @@ -38,7 +38,7 @@ ホーム