如何在Laravel中获取选定的单选按钮值

JaN*_*JaN 5 return-value radio-button laravel-4

大家好,如何获得选定的单选按钮值.我想在我的桌子上存储选定单选按钮的值.

我的Controller代码传递给View $ result

        $result =     DB::table('table')
                                ->where('name', $name)
                                ->where('code', $code)
                                ->get();

        return  View::make('home.search_result')            
                       ->with('result', $result);
Run Code Online (Sandbox Code Playgroud)

在我的视图代码中,我有单选按钮.

{{ Form::open(array('action' => 'BookingController@postValue',  'class'=>'well', 'method' => 'GET')) }}         
<table id="search" class="table table-striped table-hover">
    <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>Code</th>                                                                                                              
        </tr>
    </thead>
    <tbody> 
        @foreach($result as $result)                                    
            <tr class="success">    
                <td>{{ Form::radio('result') }}
                <td>{{ $result->name}}</td>                 
                <td>{{ $result->code}}</td>                 
            </tr>                       
        @endforeach                           
    </tfoot>
</table>           

{{ Form::submit('Add', array('class' => 'btn btn-info')) }}         
{{ Form::close() }}         
Run Code Online (Sandbox Code Playgroud)

所以当我单击Add按钮时,我尝试将chechked单选按钮值传递给我的postValue函数.

Jas*_*wis 8

您需要为单选按钮指定一个值.所有你给它的是一个名字.

<td>{{ Form::radio('result', $result->code) }}
Run Code Online (Sandbox Code Playgroud)

然后在处理表单的控制器中,您可以获取值.

$result = Input::get('result');
Run Code Online (Sandbox Code Playgroud)