skip to Main Content

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


  1. $request->only('val1', 'val2', ...);
    
    Login or Signup to reply.
  2. 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);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search