Php laravel单行动态值

Php laravel单行动态值,php,laravel,Php,Laravel,laravel单行动态值,我有2个输入列和1个下拉列,我尝试使用第1列下拉列表获取值。如果我从下拉列表中选择“值”,则会在其他两个输入列中自动显示其关联的值 我的数据库表 我想在输入列中显示此值 我的控制器 public function data() { $datas = Model::all(); return view('your view name',compact('datas')); } 我的看法 <table> <thead>

laravel单行动态值,我有2个输入列和1个下拉列,我尝试使用第1列下拉列表获取值。如果我从下拉列表中选择“值”,则会在其他两个输入列中自动显示其关联的值

我的数据库表

我想在输入列中显示此值

我的控制器

public function data() {
    $datas = Model::all();
    return view('your view name',compact('datas'));
}
我的看法

<table>
    <thead>
        <tr>
            <th class='text-center'>SL-No</th>
            <th class="text-center'>NAME</th> 
            <th class='text-center'>PART-ID</th>
            <th class='text-center'>PRICE</th>
        </tr>
    </thead>
    <tbody> 
        @foreach ($entry->datas as $key=>$datas1)
            <tr>
                <td class='text-center'>{{ $key + 1  }}</td>
                <td class='text-center  text-danger'>
                    <b>
                        <datalist>
                            @foreach ($datas $key=>$datas1)
                                <option>{{$datas1->name}}</option> 
                            @endforeach
                        <datalist>
                    </b>
               </td>
               <td class='text-center success'>{{ $datas1->part_id}}</td>
               <td class ='text-center'><b>{{ $datas1->price}}</b></td>
            </tr>
        @endforeach
    </tbody>
</table>

SL号

在视图代码中,显示表中的所有行,并且只希望显示一行“显示动态依赖于”下拉列表,以便可以使用ajax: 第一:考虑到

<table class="table">
<thead>
<tr>
    <th>id</th>
    <th>name</th>
    <th>part_id</th>
    <th>price</th>
</tr>
</thead>


<tbody>

        <tr>
            <td class='text-center' id="product_id"></td>
            <td class='text-center  text-danger' id="product_name">
                <b>
                    <select name="data" id="product-val" onchange="get_product()">
                        <option value="0"> -- select name -- </option>
                        @foreach ($datas as $key=>$datas1)
                            <option value="{{$datas1->id}}">{{$datas1->name}}</option>
                        @endforeach
                    </select>
                 </b>
            </td>
            <td class='text-center success' id="part_id"></td>
           <td class ='text-center' id="product_price"></td>
        </tr>

        </tbody>
    </table>
    <script>
     function get_product(){
      var x = document.getElementById("product-val").value;
    $.ajax({
        url: '/home/product/'+x,
        type: "GET",
        datatype: 'html',

    }).done(

        function(data)

        {
            console.log(data.id);
            $('#product_id').text(data.id);

            $('#part_id').text(data.part_id);
            $('#product_price').text(data.price);


        }

    );
   }

   </script>
和功能:

public function getproduct($id){
    $product=Data::where("id",$id)->first();
    return $product;
}

更改时选择它转到ajax获取select的值并将其发送到函数以获取所需的行,然后完成后,我用返回的数据填充表格单元格

@Spholt谢谢您的更正我在这里看不到任何使此视图动态的代码。到目前为止你试过什么?您是在寻找前端解决方案还是后端解决方案?@Spholt frontend solution
public function getproduct($id){
    $product=Data::where("id",$id)->first();
    return $product;
}