How to check Table exist or not in Database in Laravel
In this article we will learn how to check table exist or not in Laravel. Laravel provides lots of methods to functionalities to deal with different types of database requirements. Like table you can also check column exist or not in a table and DB exist or not etc. Here is a below example to check table exist or not in your connected database.
HomeController.php :-
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Schema; use DB; class HomeController extends Controller { public function checkTableExist(){ try{ $has_table = Schema::hasTable('table_name'); return $has_table; } catch(\Exception $e){ return false; } } }
If your table table exist in database then it will return true otherwise false .
Thank you for reading this article 😊
For any query do not hesitate to comment 💬