Could someone please help to understand how to create store method validation in Laravel for the table with the current structure.
Schema::create('product_areas', function (Blueprint $table) {
$table->increments('id');
$table->integer('area_id')->unsigned();
$table->integer('product_id')->unsigned();
});
The area_id
field must be unique only when it has the same product_id
within the same model.
This should be possible:
['id' => 1, 'area_id' => 1, 'product_id' => 1]
['id' => 2, 'area_id'=> 1, 'product_id' => 2]
Where this should throw an error:
['id' => 1, 'area_id' => 1, 'product_id' => 1]
['id' => 2, 'area_id'=> 1, 'product_id' => 1]
I have read the documentation but have not found similar scenario. I have very little idea of how this could be implemented.
Thank you all in advance.