前提
登録ユーザーがテストを作成し共有するシステム。
Model/Word(作成したテスト情報のテーブル)
Model/Nice(フォロー情報のテーブル)
実現したいこと
フォローしているメンバーの作成リストを全て表示したいです。宜しくお願い致します。
発生している問題・エラーメッセージ
フォロー一人目の作成リストしか表示されません。一人しかフォローしてなければ問題ないのですが、複数フォローできる様にしたいです。(複数のフォローは出来ていますが、表示できていない状態です)
※dd($follows)をすると、フォローしているユーザーは全て表示されています。
該当のソースコード
Controller.php
1/*自分がフォローしているユーザー名を取得*/ 2 $follows = Nice::where('user_id','=',Auth::user()->id)->get()->pluck('created_user')->toArray(); 3/*取得したユーザー名がテスト作成者名と一致するテストを取得する 4$ftests = Word::where('user_name','=', $follows)->orderBy('created_at', 'desc')->paginate(10);
blade.php
1<tbody id="tbl"> 2 @foreach ($ftests as $ftest) 3 <tr> 4 <td>{{ $ftest->Type->type }}</td> 5 <td>{{ $ftest->Textbook->textbook }}</td> 6 <td>{{ $ftest->test_name }}</td> 7 <td>{{ $ftest->user_name }}</td> 8 @if($ftest -> created_at > $date) 9 <td> 10 <img src="img/new.png" alt="new" style="width:30px; height:auto;"> 11 <div class="button"><a href="{{ route('test',['id'=>$ftest->id]) }}">表示</a></div> 12 </td> 13 @else 14 <td> 15 <div class="button"><a href="{{ route('test',['id'=>$ftest->id]) }}">表示</a></div> 16 </td> 17 @endif 18 @endforeach 19 </tr> 20 </tbody>
create_words_table.php
1 public function up() 2 { 3 Schema::create('words', function (Blueprint $table) { 4 $table->id(); 5 $table->string('type')->index(); 6 $table->string('textbook')->index(); 7 $table->string('test_name'); 8 $table->string('user_name')->index();/*テスト作成者名 9 $table->string('ja1'); 10 $table->string('ja2'); 11 $table->string('ja3'); 12 $table->string('ja4'); 13 $table->string('ja5'); 14 $table->string('ja6'); 15 $table->string('ja7'); 16 $table->string('ja8'); 17 $table->string('ja9'); 18 $table->string('ja10'); 19 $table->string('en1'); 20 $table->string('en2'); 21 $table->string('en3'); 22 $table->string('en4'); 23 $table->string('en5'); 24 $table->string('en6'); 25 $table->string('en7'); 26 $table->string('en8'); 27 $table->string('en9'); 28 $table->string('en10'); 29 $table->integer('count')->default(0); 30 $table->integer('alert')->default(0); 31 $table->timestamps(); 32 }); 33 }
create_nices_table.php
1 public function up() 2 { 3 Schema::create('nices', function (Blueprint $table) { 4 $table->id(); 5 $table->unsignedBigInteger('created_id')->nullable();/*フォローされた人のID 6 $table->string('created_user');/*フォローされた人のユーザー名 7 $table->unsignedBigInteger('user_id')->nullable();/*フォローした人のID 8 $table->timestamps(); 9 }); 10 }
試したこと
- コントローラー内にforeach($folllows as $follow)を入れる→同じ結果
- 同様にコントローラー内にforeach($folllows as $follow)を入れ, $ftests = Word::where('user_name','=', $follows)の$followsを$followに変更→二人目だけが表示される
補足情報(FW/ツールのバージョンなど)
Laravel Framework 8.83.16
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/01 13:57