jeudi 28 avril 2016

Check for composite unique input via Request in Laravel

I have a site that has multiple instances (companies).

Each company can add their own inventory and unit number must be unique within instance (company). But I want to allow same unit number per company. Therefore, unit+ instance_id needs to be unique. Is there a way to implement this check in Request rules?

public function rules() {
    return [
        'unit' => 'unique:mytable|required|max:45',
        'comments' => 'sometimes|max:255'
    ];
}

public function messages() {
    return [
        'unit.unique' => 'Unit number already exists!',
        'unit.required' => 'Enter Unit Number!',
        'max' => ':attribute - Should not be longer than 255 symbols!'
    ];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire