refactured my code on database.php