2017-12-01 4 views
0

ログインユーザーをドロップダウン選択値として設定しようとしましたが、ドロップダウン値のリストをチェックすると、Admin.Iのような繰り返し値が表示されます。データベースに保存されています....この問題を解決するためにお手伝いください。重複した値を表示するダイナミックドロップダウン5.2

ここでは、ユーザーのドロップダウンがあり、管理者が現在のユーザーとして選択されています。削除するクエリでLaravelブレードで

$users = User::all(); 
$current_user = Auth::user()->name; 

ダイナミックドロップダウン..

<select name="recieved_by" class="form-control"> 
    <option value="{{ $current_user }}" selected>{{ $current_user }}</option> 
    @foreach($users as $user) 
    <option value="{{$user->name}}">{{ $user->name }}</option> 
    @endforeach 
</select> 
+0

は私の答えをチェックし、それが動作するかどうか私に知らせてください。 –

答えて

0

使用はGROUPBY

enter image description here

ユーザーコントローラ重複します。

それは以下のようなあなたの選択のドロップダウンに繰り返さないように、また、クエリから現在のユーザーを削除する:あなたは、これはあなたを助けるあなたのforeach()ループ

希望を使用する前に

$current_user = Auth::user()->name; 
$users = User::where('name','!=',$current_user)->groupBy('name')->get(); 
0
$users = array(); //declare an array 

    @foreach($users as $user) 
     $users['name'] = $user->name; 
    @endforeach 
    $users = array_unique($users); 

。 laravel開発者がないですよう

構文をチェックしてください

おかげで、

+0

それは私にこのエラーを与えます array_unique()は、配列1であると想定しています。与えられたオブジェクト – ma123456

+0

$ usersはあなたの配列またはオブジェクトですか? –

+0

$ usersはオブジェクトの配列です...各オブジェクトにはユーザーのデータが含まれています – ma123456

0
<select name="recieved_by" class="form-control"> 

     @foreach($users as $user) 
      @if($current_user==$user->name) 
       <option value="{{ $current_user }}" selected>{{ $current_user }}</option> 
      @endif 
      <option value="{{$user->name}}">{{ $user->name }}</option> 
     @endforeach 

</select> 
関連する問題