简体   繁体   English

使用ID以及选择列表中的值填充数据库中的所有记录

[英]Populate all records from database with id also the values in select list

I'm having a problem where I need to populate all the values from database in my select list for the second time. 我遇到了一个问题,我需要第二次从我的选择列表中填充数据库中的所有值。 I have two select list the one is multiple list of the users . 我有两个选择列表,一个是多个users列表。 Second for the categories which I still don't have an idea. 对于我仍然不了解的categories ,其次。

Select list multiple 选择多个列表

<div class = "form-group">
    <label for = "to" class = "control-label">To:</label>
    <select class = "form-control" class="multiselect" multiple="multiple">

            @foreach ($result as $list)
                <option value = "{{ $list->id }}">{{ $list->username }}</option>
            @endforeach

    </select>
</div>

Select list one 选择清单一

<div class = "form-group">

        <label for = "category" class = "control-label">Category:</label>
            <select class = "form-control">

                @foreach ($resultCategory as $categoryList)
                <option value = "{{ $categoryList->id }}">{{ $categoryList->category_type }}</option>
                @endforeach

            </select>

</div>

Controller: as you can see here I passed the $result for the records of all user's in my return view ('document.create') 控制器:您可以在这里看到,我在return view ('document.create')传递了$result以获取所有用户的记录return view ('document.create')

public function getDocuments()
{  
    $result = DB::table('users')->where('id', '!=', Auth::id())->get();

    $resultCategory = DB::table('categories')->get();

    return view ('document.create')->with('result', $result);

} }

I'm thinking how can I passed the $resultCategory in my return view for able to populate my records from my second select list. 我在想如何在return view传递$resultCategory以便能够从第二个选择列表中填充记录。 Because I already passed the value which is $result 因为我已经传递了$result的值

I already find a solution. 我已经找到了解决方案。 I just add with ('resultCategory', '$resultCategory') for the second time. 我第二次添加('resultCategory', '$resultCategory')

$result = DB::table('users')->where('id', '!=', Auth::id())->get();

$resultCategory = DB::table('categories')->get();

return view ('document.create')->with('result', $result)->with('resultCategory', $resultCategory);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM