簡體   English   中英

Laravel PHP-將db中的set選項在選擇列表中選擇

[英]Laravel PHP - Have the the set option in db to be the selected in select list

我從數據庫中選擇兩個記錄:

    return view('customers')->with(
        [
            "customers" => DB::table('people')
                ->leftJoin("statuses", "people.status", "=", "statuses.id")
                ->where('type', 'customer')
                ->get()->toArray(),
            "statuses"  => DB::table("statuses")->get()->toArray()
        ]);

每個customer都有一個代表statuses.idstatus列。

現在我認為:

                            @foreach ($customers as $customer)
                                <tr>
                                    <td>{{$customer->id}}</td>
                                    <td>{{$customer->first_name}} {{$customer->last_name}}</td>
                                    <td>{{$customer->country_id}}</td>
                                    <td>{{$customer->phone_number}}</td>
                                    <td>{{$customer->created_at}}</td>
                                    <td>{{$customer->email}}</td>
                                    <td>{{$customer->campaign}}</td>
                                    <td>
                                        <select>
                                            @foreach($statuses as $status)
                                                <option>{{$status->title}}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                            @endforeach

我打印了所有狀態,但是我想將所選狀態設置為我與其他people加入的ID

最佳做法是什么?

您需要根據狀態ID檢查客戶狀態

  <select>
     @foreach($statuses as $status)
        <option @if($customer->status == $status->id) selected="selected" @endif>{{$status->title}}</option>
     @endforeach
  </select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM