laravellaravel-blade

How to show DBMS name and version in laravel view?


I want to show a status bar in a laravel website. Which will show the DBMS name and version number. The output I want is like

PostgreSQL 9.2.24

Or

MySQL 5.6

I can get the name of database by using env('DB_CONNECTION'). It is giving me the name(although, it is showing 'pgsql'; not 'PostgreSQL ').

However, I don't understand how can I get the version number in view. What is the way to get the version number?


Solution

  • You can use DB::raw() to create database raw expression.

     $version = DB::select( DB::raw("select version()"));
    

    pass the value to your view.

    In Laravel 10 it is

    DB::select( "select version()" )[0]->{'version()'}