skip to Main Content

I need help in Laravel.

I need to list all VIEWS from db.

I have written this query in my Controller:

$reports = DB::select("Select TABLE SCHEMA", TRIM('r_all_' FROM TABLE_NAME) as viewname FROM       information_schema.tables WHERE TABLE_TYPE LIKE 'VIEW' AND table_schema LIKE 'mprm_shared' AND TABLE_NAME     LIKE 'r_all_%'");

With this code I am getting all the views, but in my Model I have only this code:
protected $table = ‘r_all_users’;

With this code I can see the table only from this view: r_all_users.

What I need to change to display tables from All VIEWS, not only from r_all_users?

I need help in my code and I think it is good to ask this

2

Answers


  1. you can:
    Lists all the tables in all databases

    SELECT table_name
    FROM information_schema.tables
    WHERE table_type='BASE TABLE'
    

    Lists all the tables in a particular database

    SELECT table_name
    FROM information_schema.tables
    WHERE table_type='BASE TABLE'
          AND table_schema = 'your_database_name'
    
    Login or Signup to reply.
  2. You can use laravel Schema method getAllTables()

    use IlluminateSupportFacadesSchema;
    
    ...
    
    Schema::getAllTables();
    

    It would return an array that contains all table names.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search