SQLSTATE[23000]

问题描述 投票:0回答:1

我对 laravel 的 phpmyadmin 有疑问 我想通过控制器更新数据库视图中的数据,但出现错误

    // 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();
    }

当我尝试更新数据时出现错误

它是我的数据库

php laravel controller foreign-keys relationship
1个回答
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();
}
© www.soinside.com 2019 - 2024. All rights reserved.