laravelpostgresqlschemalaravel-8information-schema

How to check a table exists in another schema


How to check if a table exists in a given schema using laravel.

eg: I want to check if a table exists in acc schema I tried this but did not get.

$apty_tblnme = 'acc.accounts_appropriation_allotment_types'; 

$apty_exist = (!Schema::hasTable($apty_tblnme));//--if table not, get 1,
                   

Solution

  • $apty_tblnme = DB::connection('pgsql') ->select("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ? AND table_name = ?)",['acc','xxx']);

    here, acc-schema, xxx- table name