I have in the creation migration of my table the following:
public function up()
{
Schema::connection('database2')->create('empresa_funcoes', function(Blueprint $table) {
$table->increments('id');
$table->integer('empresa_id')->unsigned();
$table->integer('funcao_id')->unsigned();
$table->timestamps();
//Create a Unique Constraint
$table->unique(['empresa_id', 'funcao_id'], 'empresa_funcao');
//Create Foreign Keys
$table->foreign('empresa_id')->references('id')->on('empresas')->onDelete('cascade');
$table->foreign('funcao_id')->references('id')->on('funcoes')->onDelete('cascade');
});
}
In my request I need to create a constraint so that I can not register a 2x function for the same company.
I have this so far in my CompanyFunctionRequest, but I can not just put a unique
there because it will not let me register that role for another company.
public function rules()
{
return [
'funcao_id' => 'required',
];
}
What can I do?
I'm not asking to validate the empresa_id because it's going on a hidden, I do not know if it influences.