How to select all column name from a table in laravel

0 votes

I have tried to get all column names from a table Teller

Function:

public function getTableColumns($tables)
{
    return DB::select(DB::raw('SELECT 
                                    COLUMN_NAME, 
                                    DATA_TYPE, 
                                    COLUMN_DEFAULT
                                FROM 
                                    INFORMATION_SCHEMA.COLUMNS
                                WHERE 
                                    table_name = `Teller`'));
}
Dec 2, 2020 in Laravel by kartik
• 37,510 points
5,969 views

1 answer to this question.

0 votes

You can get all columns name by simply doing this:

use Illuminate\Support\Facades\Schema;

use Illuminate\Support\Facades\DB;

public function getTableColumns($table)
{
    return DB::getSchemaBuilder()->getColumnListing($table);

    // OR

    return Schema::getColumnListing($table);

}
answered Dec 2, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How to gett selected values from a multiple select form in Laravel?

Hello @kartik, First, if you want to have ...READ MORE

answered Oct 21, 2020 in Laravel by Niroj
• 82,880 points
6,898 views
0 votes
1 answer

How to update a pivot table using Eloquent in laravel 5?

Hello @kartik, The code below solved my problem: $messages ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,880 points
4,091 views
0 votes
1 answer

How to return database table name in Laravel?

Hello @kartik, There is a public getTable() method ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,880 points
2,671 views
0 votes
1 answer

How to alias a table in Laravel Eloquent queries using Query Builder?

Hello @kartik, You can use less code, writing ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,880 points
10,009 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,874 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,678 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,540 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,710 views
+2 votes
2 answers

How to add a new column to existing table of laravel in a migration?

You need do little modification in your ...READ MORE

answered Dec 10, 2020 in Laravel by anonymous
• 82,880 points
119,936 views
0 votes
1 answer

How to select year and month from the created_at attributes of database table in laravel 5.1?

Hello @kartik, There are date helpers available in ...READ MORE

answered Sep 30, 2020 in Laravel by Niroj
• 82,880 points
14,238 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP