我想在 Laravel 中跨数据库事务,我在 DB 中使用了连接,但它无法正常工作,它给出了一个错误,如(一般错误:1205 Lock wait timeout exceeded; try restarting transaction)
class User extends Model
{
protected $connection = 'mysql';
}
class StudentDetail extends Model
{
protected $connection = 'tenant';
}
public function update($id){
try {
//in Controllerfile
//Default connection is 'tenant'
DB::beginTransaction();
DB::connection('mysql')->beginTransaction();
//create a role
$student = StudentDetail::find($id)
$student = student->update([
'name' => $request->name,
'type' => $request->type
]);
$user= Auth::user();
$uesr->last_accessed_date = date('Y-m-d H:i:s');
$uesr->update();
DB::commit();
DB::connection('mysql')->commit();
}
catch (Exception $e) {
DB::rollBack();
DB::connection('mysql')->rollBack();
}
return response()->json(['status' => true, 'message' => 'success']);
}