How to Get Table Name from Model in Laravel?
If you need to get table name from model in your laravel application then this post can help you to get table name in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 app. Laravel based on MVC. So, we require to create model for every table that way we can write database logic on model. But if you require to get table name from model then you can get using getTable() of model.
Laravel eloquent model provide several methos like for all(), get(), first() etc, that helps to get table record from model table.
You can get table name simply call getTable() of model object, so how to call this method as bellow example.
Example:
$item = new Item;
$table = $item->getTable();
print_r($table);
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 10 Model Events Example Tutorial
- How to Add Custom Attribute in Laravel Model?
- Laravel Model Disable Primary Key & Auto Increment Example
- Get Array of Ids from Eloquent Models in Laravel
- How to Set Default Value in Laravel Model?
- How to Select Specific Columns in Laravel Eloquent Model?
- How to Get All Models in Laravel?
- How to Get Columns Names from Model in Laravel?
- How to Create Model in Laravel using Command?
- How to Create Custom Model Events in Laravel?
- Laravel Model Events Tutorial
- Laravel Eloquent Delete Record By ID Example
- Delete All Records from Table in Laravel Eloquent
- How to disable model timestamps in Laravel?