我有三个模型:活动模型,客户模型和客户模型
如何在商店功能中进行验证检查,在每个活动中客户名称应该是唯一的?
以下是每个迁移文件
活动模型
public function up()
{
Schema::create('activities', function (Blueprint $table) {
$table->increments('id');
$table->string('activityName');
$table->string('activityCode');
$table->string('activityVenue');
$table->timestamps();
});
}
客户模式
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->integer('activities_id')->unsigned()->default(0);
$table->foreign('activities_id')->references('id')->on('activities')->onDelete('cascade');
$table->text('remark')->nullable();
$table->timestamps();
});
}
客户模型
public function up()
{
Schema::create('customeritems', function (Blueprint $table) {
$table->increments('id');
$table->integer('customers_id')->unsigned()->default(0);
$table->foreign('customers_id')->references('id')->on('customers')->onDelete('cascade');
$table->string('customerName');
$table->integer('customerAge')->unsigned();
$table->timestamps();
});
}
存储新条目的控制器
public function store(Request $request)
{
$rules = array(
'customerName' => 'required|distinct',
);
$messages = array(
'customerName.required'=>'Customer Name is required',
'customerName.distinct'=>'Customer Name has a duplicate value.',
);
此处如何为每项活动的唯一customerName进行验证?