表单更新最后创建的数组而不是所选数组的数据

时间:2019-01-10 17:26:56

标签: php mysql laravel laravel-5

我有一个表单,当选择一个已经存在的数组并尝试对其进行编辑时,它将显示正确的信息。 但是在保存时,它将所有信息保存到最后创建的数组中并替换它。

任何人都知道可能是什么原因造成的吗?

控制器:

/**
 * update job detail in database
 */

public function updateJob(Request $request, $id){
    $this->validate($request, [
        'title' => 'required|max:50',
        'category' => 'required|numeric',
        'last_date' => 'required',
        'description' => 'required|min:20',
        'city' => 'required',
        'vacancies' => 'nullable|numeric',
    ]);

    $job = Posts::find($id);

    $setting = Settings::first();
    $company = Companies::where('user_id', Auth::id())->first();

    $job->title             = $request->title;
    $job->description       = $request->description;
    $job->type              = $request->type;
    $job->cat_id            = $request->category;
    $job->experience        = $request->experience;
    $job->city_id           = $request->city;
    $job->total_vacancies   = $request->vacancies;
    $job->job_type_id       = $request->job_type;
    $job->salary            = $request->salary;
    $job->last_date         = Carbon::createFromFormat('d/m/Y', $request->last_date);                            
    $job->shift             = $request->shift;
    $job->status            = 'active';


    $job->save();

谢谢。

0 个答案:

没有答案