Laravel 无法保存值选择选项
我的项目出了什么问题。 我想用select选项保存,但该字段没有保存数据select选项。它只保存输入文本。 项目采用不同的表,表单只获得Laravel 无法保存值选择选项,laravel,select,view,option,Laravel,Select,View,Option,我的项目出了什么问题。 我想用select选项保存,但该字段没有保存数据select选项。它只保存输入文本。 项目采用不同的表,表单只获得project\u name和project\u id项目id将保存在表花费的时间中。 选择选项将在表花费的时间中保存任务类别 这是我的模型 protected $table = 'spent_times'; protected $fillable = [ 'task_category', 'story/meeting_name', '
project\u name
和project\u id
<代码>项目id将保存在表花费的时间
中。
选择选项将在表花费的时间中保存任务类别
这是我的模型
protected $table = 'spent_times';
protected $fillable = [
'task_category',
'story/meeting_name',
'assign',
'estimated_time',
'user_story',
'spent_time',
'percentage',
'lateness',
'index',
'project_id'
];
public function users() {
return $this->hasMany(User::class);
}
public function project() {
return $this->belongsTo(Project::class);
}
my create.blade.php
<form action="{{route('store')}}" method="POST">
@csrf
<div class="box-body">
<div class="form-group">
<label for="">Project *</label>
<select class="form-control select2" style="width: 100%;">
<option>Select One</option>
@foreach($projects as $id => $project)
<option value="{{$id}}">{{$project}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="">Story # Meeting Name *</label>
<input type="text" class="form-control" name="user_story">
</div>
<div class="form-group">
<label for="">Category *</label>
<select class="form-control select2" style="width: 100%;">
<option>Select One</option>
@foreach($task_categories as $category)
<option value="{{$category}}">{{$category}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="">Estimated *</label>
<input type="text" class="form-control" name="estimated_time">
</div>
</div>
<div class="box-footer">
<a href="{{route('index')}}">
<button type="submit" class="btn btn-primary col-md-12" style="border-radius : 0px;">SAVE</button>
</a>
</div>
</form>
这样的错误
请帮助我您希望中的请求包含这些字段
project\u id
会议名称
任务\u类别
估计时间
但您只是发送了估计时间
,
其他3个字段在您的中不存在
在create.blade.php中,类别选择输入没有任何名称。
这就是为什么task\u category
从request('task\u category')
得到空值的原因。但是在数据库表中,task\u category
字段不能为空
按照控制器中的预期正确发送表单输入。您可以使用dd($request->all())
进行检查 我相信这是您的任务类别
选择框
因此,此选择框没有名称属性。这就是错误所在
可能的解决办法
<div class="form-group">
<label for="">Category *</label>
<select name="task_category" class="form-control select2" style="width: 100%;">
<option>Select One</option>
@foreach($task_categories as $category)
<option value="{{$category}}">{{$category}}</option>
@endforeach
</select>
</div>
类别*
选择一个
@foreach($task\u categories作为$category)
{{$category}
@endforeach
您的SpentTime::create()
函数参数与数据库中的花费时间
表列不匹配。首先使用dd($request->all())检查$request
代码>此my model protected$表='花费的时间';受保护的$fillable=[‘任务类别’、‘故事/会议名称’、‘分配’、‘估计时间’、‘用户故事’、‘花费时间’、‘百分比’、‘迟到’、‘索引’、‘项目id’];公共函数用户(){return$this->hasMany(User::class);}公共函数项目(){return$this->belongsTo(project::class);}我可以在两个不同的表中创建一个字段吗?最重要的是表结构和$request
值列表。因为当我使用dd($request->all())时,$request
中似乎没有task\u caegory
field task\u类别没有在dbi中发布我只是在我的dbstill错误中发送了某些字段,tas\u类别没有发送数据。你能把dd($request->all())
的输出显示为屏幕截图吗?这是屏幕截图dd($request->all())
!
<div class="form-group">
<label for="">Category *</label>
<select name="task_category" class="form-control select2" style="width: 100%;">
<option>Select One</option>
@foreach($task_categories as $category)
<option value="{{$category}}">{{$category}}</option>
@endforeach
</select>
</div>