[英]How to get selected checkbox value in edit blade Laravel
I'm trying to get the selected checkbox value on the edit blade page.我正在尝试在编辑刀片页面上获取选定的复选框值。
I'm using a query that is used to get student role from users table.我正在使用一个用于从用户表中获取学生角色的查询。
Code in edit.blade.php
edit.blade.php
代码
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Students :</strong>
<div style="margin-top: 5px" >
<?php
$conn = new mysqli('localhost', 'root', '', 'rp') or die ('Cannot connect to db');
$result = $conn->query("select users.id, users.name from users, model_has_roles where model_has_roles.model_id=users.id and model_has_roles.role_id=14;
");
//echo "<select name='name'>";
echo "<html>";
echo "<body>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<input type=checkbox name="student_id[]" id="student" value="'.$id.'" '.(($ticket->$id == 'student_id' ? 'checked' : '' )).' >'.$name.'';}
echo "</body>";
echo "</html>";
?>
also trying to use other way echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
还尝试使用其他方式
echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
But still nothing shown.但仍然没有显示。
I would be very thankful if anyone could point-out mistake I'm doing here.如果有人能指出我在这里做的错误,我将非常感激。
试试这个代码:
<input type="checkbox" value="1" {{$ticket->$id == 'student_id' ? 'checked' : ''}}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.