I just wanted to add the following for people from search engines:
If you donβt even want to instantiate a Model (faster?):
$model = 'App\User'; $modelTable = str_replace('\\', '', Str::snake(Str::plural(class_basename($model)))); dd($modelTable); // will return "users"
This may seem ugly, but thatβs exactly how the getTable () method resolves this discreetly, so ...
You will need to use Illuminate\Support\Str; on top of your file.
Application: it is understood that you follow the framework standards (i.e.: the Post model has a posts table, the user model has a users table, etc.)
13h50
source share