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

jmacdiarmid's avatar

required field if client is logged in.

I'm looking for suggestions and a point to reference how to show/validate client signature fields. I have a web development/digital advertising contract form with a payment / approval section that contains a few text boxes and a signature pad. I need to require and display these fields if a client is logged in. not required/displayed if an admin or sales staff is logged in.

I was looking at the "required_if", "required_unless", etc. validation clause(?). I currently have Laravel Breeze installed. Will this work or would I need something more to handle roles (and permissions).

At the moment, I only have basic rules set up which looks like this.

 protected array $rules = [
        'contract.first_name_on_account' => 'required|string',
        'contract.last_name_on_account' => 'required|string',
        'contract.client_signature' => 'required|string',
        'contract.client_name_printed' => 'required|string',
        'contract.consultant_signature' => 'required|string',
        'contract.consultant_name_printed'  => 'required|string'
    ];
0 likes
1 reply
bugsysha's avatar

If you create a form request, you can check if the user is authenticated, and which type of a user, and based on that return appropriate rules from the rules method.

public function rules(): array
{
    $rules = [
        'name' => 'required|boolean',
    ];

	if ($this->user()) { // this is to check if they are logged in
		$rules['something'] = 'required|string';
	}

	if ($this->user()->isSomething()) { // here you check for a type
		$rules['something-else'] = 'required|string';
	}

    return $rules;
}

Please or to participate in this conversation.