Summer sale! Save 50% on access to our entire library of courses.Join here →

Getting the Table Name From a Model in Laravel

1 episode 3 mins

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!

Episodes

0%
Your progress
  • Total: 3m
  • Played: 0m
  • Remaining: 3m