How to get all data from database in Laravel

get all data from database in laravel 8

In this article we will learn about how to get all data from database in laravel , I will show you how to get all table in the from the database, then I will show you how to get all table column in laravel.

Get all table name from the database in laravel

In the below code I will show how we can get all tabel name from the database in laravel

$tables_list = DB::select('SHOW TABLES');
dd($tables_list);

when you run the above code, you will have output like the below one.

all table list from database in laravel

Get all the column name of the given table

To the all the column name of the given table,use the below code.

$tableColumns = DB::connection()->getSchemaBuilder()->getColumnListing('Your_table_name');
dd($tableColumns);

when you run the above code you have the output like the below image.

all the table column name from database in laravel

0 0 vote
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x