Laravel 4 - Cannot catch database exception in seed or migration class

前端 未结 2 1494
感情败类
感情败类 2021-01-13 17:13

Laravel 4 with MySql db. For some reason, I cannot catch DB exceptions (Illuminate\\Database\\QueryException) inside a seed or migration class: the code nev

2条回答
  •  伪装坚强ぢ
    2021-01-13 17:36

    You must catch "Illuminate\Database\QueryException"

    try {
        $data = array('id' => 1, 'name' => 'foo');
        DB::table('table')->insert($data);
    }
    catch (\Illuminate\Database\QueryException $e) {
        $this->command->error("SQL Error: " . $e->getMessage() . "\n");
    }
    

提交回复
热议问题