
How to get Database Table Name From Laravel Eloquent Model?
Hello Everyone, In this article, I will show some tips to get your database table using eloquent.
For instance, if you need to get a database table name from any model in your laravel application. Based on MVC Architecture. There are few ways of doing such, but many use this approach which is common in the laravel community. getTable().
Laravel eloquent model provides several methods like for all(), get(), first(), etc, that helps to get table record from the model table.
You can get a table name by simply calling getTable() of the model object, So let's see how to call this method as below example.
Example:
$user = new User;
$tableName = $user->getTable();
dd($tableName);
Thank you for reading this article, if you have anything that you wanted to ask leave your comment and we discuss it. I hope you understand a How to get Database Table Name From Laravel Eloquent Model? by now.
0 Comments