The usage of transaction in laravel

is it okay to write transactions like this, and do you need custom exceptions?

DB::beginTransaction();
try{
    // 
    $adminRoleObj = new AdminRole;
    $result = $adminRoleObj->deleteAdminRole($admin->id);

    // 
    $result = $admin->delete();

    DB::commit();
}catch(\Exception $e){
    $result = false;
    Log::error("admin:delete ".$e->getMessage());
    DB::rollBack();
}

clipboard.png

May.05,2021

Congratulations, the writing is correct, there is no doubt.
there is no need to customize exceptions in your business of directly manipulating the library. Database execution errors or exceptions will throw exceptions themselves.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31495-2bd85.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31495-2bd85.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?