Getting the Table Name From a Model in Laravel

1 episode 3 mins

Course overview

Sometimes we need to reference table names throughout our codebase, like when we're using the DB facade.

Although table names don't change often, I still get an uneasy feeling hardcoding them. It's so much better to reference the model directly so we have one source of truth for the table name.

So, let's learn how to do that! We'll also create a trait that allows static access to any of our model table names to keep our code a little tidier.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!