I want to remove the directory that gets created when I record in the database is inserted. I have something like this.
$model->dir = MyClass->createDirectory();
\DB::transaction(function(){
$model->save(); // fails
});
MyClass->removeDirectory(); //this will be execute upon failure.
I'm not asking about try catch block with transactions. I am asking how to execute a block of code if transaction fails.