Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nine's avatar
Level 1

authorize null field on create but make it required on update

Hello,

I have 3 linked tables. Let's call them table 1 , table 2 and table 3. The table 2 is not managed on my app, it's only necessary for gather informations between 1 and 3 table.

So i plan to create a db::transaction with :

insert new row in table 1 insert 10 rows in table 2 in for loop with id of table 1 insert 3 rows for each of 10 rows inserted below (with ids of table 2)

For that, i have one form and this is on validation of this form that i need to make 2 fields of table 2 as required.

But i'm stuck with this. Any help is welcome ! Thanks nine

0 likes
2 replies
Jaytee's avatar

So as per your title, you're just wanting to make the fields nullable on create, and required on update?

Well you should already have two different methods, one for creating and one for updating, so just update the validation rules accordingly.


public function store()
{
    $data = request()->validate([
        'field_one' => 'nullable'
    ]);
}

public function update($theResourceOrID)
{
    $data = request()->validate([
        'field_one' => 'required'
    ]);
}
nine's avatar
Level 1

god ! so simple ! i'll try this

Thank you ;)

Please or to participate in this conversation.