0

I'm looking for a way to loop through all my database tables in Laravel in order to add a search functionality to my website.

I guess there should be a way to do this without hardcoding all the table names.

1 Answer 1

1

You can do this:

$tables = DB::select("select table_name from information_schema.tables where table_schema='your_database_name'");

Just change your_database_name to your own value. Then you can use the Laravel helper function, array_pluck, to get an array of the table_name values.

array_pluck($tables, 'table_name')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer! Is there a way to search in EVERY column without hardcoding every column name?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.