需要帮助验证(唯一验证)两个输入的组成(即事件日期和时间),以确定它们是否已被使用 .
已经使用迁移将相关的两列作为数据库上的复合键 .
目前,它在提交重复条目时提供SQL查询异常 . (SQLSTATE [2300]:完整性约束违规:1062重复条目)
Here is my table migration
Schema::create('events', function (Blueprint $table) {
$table->increments('id');
$table->string('email');
$table->string('fname');
$table->string('lname');
$table->date('event_date');
$table->string('t_session');
$table->unique(array('event_date', 't_session'));
$table->timestamps();
});
here what happens when I submit My Form
$event = new Event;
$event->email = $request->input('email');
$event->event_date = $request->input('event_date');
$event->t_session = $request->input('t_session');
$event->fname = $request->input('fname');
$event->lname = $request->input('lname');
$event->save();
return redirect('/events')->with('success', 'Event Created Successfully');
1 回答
在laracast讨论中找到答案:[https://laracasts.com/discuss/channels/laravel/how-validate-unique-combination][1]