SQLSTATE [23000]

时间:2015-11-29 13:37:36

标签: laravel controller phpmyadmin foreign-keys relationship

我对laravel的phpmyadmin有困难 我想通过控制器从db上的视图更新数据但是我发生错误

    // save all seats
    foreach ($request->all() as $key => $param) {
        if ($key === '_token') continue;

        $data = explode('-', $key);

        $bs = new BookedSeat();
        $bs->booking_id = $booking->id;
        $bs->day_id = str_replace('c', '', $data[0]);
        $bs->table_id = str_replace('t', '', $data[1]);
        $bs->number = 0;
        $bs->status = 'requested';
        $bs->save();
    }

its an error when i try update data

its my db

1 个答案:

答案 0 :(得分:0)

更新了

 // save all seats
foreach ($request->all() as $key => $param) {
    if ($key === '_token') continue;

    $data = explode('-', $key);

    $bs = new BookedSeat();
    $bs->booking_id = $booking->id;
    $day = DB::table('days')->where('name',$data[0])->get(); 
    $bs->day_id = $day->id;
    $bs->table_id = str_replace('t', '', $data[1]);
    $bs->number = 0;
    $bs->status = 'requested';
    $bs->save();
}