如何在编辑中获取选中的复选框值 blade Laravel
How to get selected checkbox value in edit blade Laravel
我正在尝试获取编辑 blade 页面上选中的复选框值。
我正在使用一个查询来从用户那里获取学生角色 table。
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>";
?>
也在尝试使用其他方式echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
但仍然没有显示。
如果有人能 point-out 弄错我在这里做的,我将不胜感激。
这不是 laravel 问题。但是您可以在输入标签内使用条件后值属性。
试试这个代码:
<input type="checkbox" value="1" {{$ticket->$id == 'student_id' ? 'checked' : ''}}/>
我正在尝试获取编辑 blade 页面上选中的复选框值。
我正在使用一个查询来从用户那里获取学生角色 table。
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>";
?>
也在尝试使用其他方式echo 'echo '<input type=checkbox name="student_id[]" value="'.$id.'" '.( (is_array(old('student_id')) && in_array($id, old('student_id'))) ? ' checked' : '' ).' >'.$name.'';
但仍然没有显示。
如果有人能 point-out 弄错我在这里做的,我将不胜感激。
这不是 laravel 问题。但是您可以在输入标签内使用条件后值属性。
试试这个代码:
<input type="checkbox" value="1" {{$ticket->$id == 'student_id' ? 'checked' : ''}}/>