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()
2
Answers
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 thenEtudiant::update($validated);