Jquery Laravel-动态输入字段未保存任何记录
使用Laravel-5.8,我想使用动态输入将多个数据保存到数据库中 存储请求Jquery Laravel-动态输入字段未保存任何记录,jquery,laravel,Jquery,Laravel,使用Laravel-5.8,我想使用动态输入将多个数据保存到数据库中 存储请求 class StoreAppraisalGoalRequest extends FormRequest { public function authorize() { return \Gate::allows('appraisal_goal_create'); } public function rules() { return [ 'goal_title' =&g
class StoreAppraisalGoalRequest extends FormRequest
{
public function authorize()
{
return \Gate::allows('appraisal_goal_create');
}
public function rules()
{
return [
'goal_title' => 'required|min:5|max:100',
'goal_type_id' => 'required',
'weighted_score' => 'required|numeric|min:0|max:500',
'start_date' => 'required',
'end_date' => 'required|after_or_equal:start_date',
'appraisal_goal_id' => 'required',
'kpi_description' => 'required|max:300',
'activity' => 'required|max:300',
];
}
}
模型
评价的
protected $fillable = [
'goal_type_id',
'appraisal_identity_id',
'employee_id',
'company_id',
'is_published',
'is_approved',
'weighted_score',
'employee_comment',
'line_manager_comment',
'goal_title',
'start_date',
'end_date',
'created_by',
'created_at',
'updated_by',
'updated_at',
'is_active'
];
AlgoAlDetail
protected $fillable = [
'name',
'company_id',
'appraisal_goal_id',
'kpi_description',
'appraisal_doc',
'activity',
'created_by',
'created_at',
'updated_by',
'updated_at',
'is_active'
];
控制器
public function create()
{
$userCompany = Auth::user()->company_id;
$identities = DB::table('appraisal_identity')->select('appraisal_name')->where('company_id', $userCompany)->where('is_current', 1)->first();
$goaltypes = AppraisalGoalType::where('company_id', $userCompany)->get();
$categories = AppraisalGoalType::with('children')->where('company_id', $userCompany)->whereNull('parent_id')->get();
return view('appraisal.appraisal_goals.create')
->with('goaltypes', $goaltypes)
->with('categories', $categories)
->with('identities', $identities);
}
public function store(StoreAppraisalGoalRequest $request)
{
$startDate = Carbon::parse($request->start_date);
$endDate = Carbon::parse($request->end_date);
$userCompany = Auth::user()->company_id;
$appraisal_identity_id = AppraisalIdentity::where('company_id', $userCompany)->where('is_current',1)->value('id');
try {
$goal = new AppraisalGoal();
$goal->goal_type_id = $request->goal_type_id;
$goal->appraisal_identity_id = $appraisal_identity_id;
$goal->employee_id = $request->employee_id;
$goal->weighted_score = $request->weighted_score;
$goal->goal_description = $request->goal_description;
$goal->start_date = $startDate;
$goal->end_date = $endDate;
$goal->company_id = Auth::user()->company_id;
$goal->created_by = Auth::user()->id;
$goal->created_at = date("Y-m-d H:i:s");
$goal->is_active = 1;
$goal->save();
foreach ( $request->activity as $key => $activity){
$goaldetail = new AppraisalGoalDetail();
$goaldetail->kpi_description = $request->kpi_description[$key];
$goaldetail->appraisal_doc = $request->application_doc[$key];
$goaldetail->activity = $request->activity[$key];
$goaldetail->appraisal_goal_id = $goal->id;
$goaldetail->company_id = Auth::user()->company_id;
$goaldetail->created_by = Auth::user()->id;
$goaldetail->created_at = date("Y-m-d H:i:s");
$goaldetail->is_active = 1;
$goaldetail->save();
}
Session::flash('success', 'Appraisal Goal is created successfully');
return redirect()->route('appraisal.appraisal_goals.index');
} catch (Exception $exception) {
Session::flash('danger', 'Appraisal Goal creation failed!');
return redirect()->route('appraisal.appraisal_goals.index');
}
}
主要的模型类是algoal
视图刀片
创建我的3+1目标:{{$identies->evaluation_name}
@csrf
目标类型:*
选择目标类型
@foreach($categories作为$category)
@除非($category->name===‘工作基础’)
id==old('category_id')?'所选“:”}>{{$category->name}
@如果($category->children)
@foreach($category->children as$child)
@除非($child->name==‘工作基础’)
id==old('category_id')?'所选“:”}>{{$child->name}
@结束语
@endforeach
@恩迪夫
@结束语
@endforeach
目标名称:*
目标描述
活动*
KPI说明*
附件
\不+
' ';
$('tbody').append(addRow);
addRemoveListener();
};
addRemoveListener();
});
函数addRemoveListener(){
$('.remove')。在('click',函数(){
变量l=$('tbody tr')。长度;
如果(l==1){
警报('您不能删除最后一个')
}否则{
$(this.parent().parent().remove();
}
});
}
你能分享你的请求对象吗?@GeorgeHanson-当我添加$data=$request->all()时,我已经在更新的代码中分享了它;打印(数据);出口我得到了一个数组([\u token]=>JW2W64I6Iso1Joy3FatyWTJK3FTBTH0CHGHXNVO[goal\u type\u id]=>2[Validation\u identity\u id]=>8[goal\u title]=>JLDFJKDSJKJK[goal\u description]=>数组([0]=>activity2[1]=>activity3][kpi\u description]=>数组([0]=>kpi描述]=>kpi描述2[1]=>kpi描述3)[评估单]=>数组([0]=>[1]=>)[加权评分]=>25[开始日期]=>2020-01-30[结束日期]=>2020-03-21),但仍不保存