I'm trying to create a table with : Etudiant::create($request->all());
But actually there is some field that I don't need from the requedt but I need them for another table; So I'm wondering if there is a function or something to add an exception to the ->all()
CodePudding user response:
$request->only('val1', 'val2', ...);
CodePudding user response:
If you want to whitelist fields:
$request->only('valueField1', 'valueField2');
or you may want to blacklist :
$request->except('valueField', 'valueField1');
Both not much safe enough tho.
I'd handle requests like this:
$validated = $request->validate(['valueField' => 'required|validation_types']);
Validated fields that you're wanting to use and then:
Etudiant::create($validated);
Note: For update case there is nullable field then use array_filter($validated);
this will remove null fields and then Etudiant::update($validated);