To get Database Name in laravel, there are various ways, here are few of them you can found to get it easily in laravel using DB/Config. Read more
To check if foreign key exists in laravel is a common issue working with the foreign key to check hasForeignKey('table','column') exists or not in a boolean response mostly. Read more