Combine Fields for checking

Posted 3 years ago by gvauditor

Hi,

Good day! I'm new to laravel and I would like to know how to use the required validation to combine fields for checking, for example I want to insert an employee record in the database in procedural way I can have a query like this: For new:
SELECT id FROM employee WHERE firstname = '$fname' AND midname = '$midname' AND lastname = '$lastname' For update: SELECT id FROM employee WHERE firstname = '$fname' AND midname = '$midname' AND lastname = '$lastname' AND id != '$id'

if the count returns 1 it means it's already being used. So far I have this one in the validation,

public function rules()
{
    return [
        'fname' => 'required|unique:manpower,firstname',
        'midname' => 'required|unique:manpower,midname',
        'lname' => 'required|unique:manpower,lastname'
    ];
}

Thank you.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.