首页 > 解决方案 > 我需要从带有所选项目 id 的输入中获取值并将它们返回给控制器

问题描述

我是 Laravel 的新手,我正在尝试使用选定元素的 id 获取输入值。

当我试图在控制器中获取数量的输入值时,它实际上是空的。

这是我的代码。

收集刀片.php

@foreach($reagentcard as $r)
                            <tr>
                            <td>{{ $i++ }}</td>
                            <td>{{ $r->casnumber }}</td>
                            <td>{{ $r->name }}</td>
                            <td>{{ $r->description }}</td>
                            <td>{{ $r->classification }}</td>
                            <td>{{ $r->manname }}</td>
                            <td>{{ $r->incomedate}} </td>
                            <td>{{ $r->expirationdate}} </td>
                            <td>{{ $r->quantity }} </td>
                            <td><input class="form-control" type="number" name="quantity"></td>
                            @if($message = Session::get('info'))
                            <strong style="color:red">{{ $message }}</strong><br>
                            @endif
                            @if($message = Session::get('error'))
                            <strong style="color:red">{{ $message }}</strong><br>
                            @endif
                            <td><a href=" {{ route('collect',['id' => $r -> id]) }}"><button> Collect </button></a> </td>
                        @endforeach

控制器.php

public function collectReagent($id, Request $request)
{
    $user_id = Auth::user()->id;
    $takedate = Carbon::now();
    $reagentcard = ReagentCard::where('id',$id)->first();
    $test = $request->route('quantity');
    return view('test',compact('test', 'id'));
}

标签: phplaravelrequest

解决方案


推荐阅读