Laravel merge with $request

Asked by At

I'm trying to merge current user id with with a laravel $request and aftr merging all data will be saved into DB. After execution data save into DB but id save as a null value. Please see my code

public function store(Request $request, ClassModel $model)
{
    $model->create($request->merge(['created_user_id' => Auth::user()->id])->all());

    return redirect()->route('class.index')->withStatus(__('Class successfully created.'));
}

Can anyone tell me why user id dont save in DB.

1 Answers

1
nakov On Best Solutions

Your field is probably nullable but then in your $fillable array of the model (which is used for mass assignment protection), you forgot to include the created_user_id column. Please check that.