To check if a table exists in a database using Pest test in Laravel, you can use the following code: it('checks if table exists in the database', function () { $tableName = 'your_table_name_here'; $exists = Schema::hasTable($tableName); expect($exists)->toBeTrue(); }); In the above code: it is a function provided by Pest that allows you to define a test case. $tableName is a variable that holds the name of the table you want to check for existence. Schema::hasTable($tableName) is a method provided by Laravel's Schema Builder that returns a boolean value indicating whether the table exists in the database or not. expect($exists)->toBeTrue() is an assertion provided by Pest that checks if the value of $exists is true.

it('checks if table exists in the database', function () { $tableName = ['table1', 'table2', 'table3']; foreach($tableNames as $tableName){ $exists = Schema::hasTable($tableName); expect($exists)->toBeTrue(); }});
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners