Looking to hire Laravel developers? Try LaraJobs

laravel-get-table-name maintained by theoluirard

Description
A package that adds a trait to the Laravel Model class and extends the Laravel Relation class with two new types of relations.
Author
Last update
2025/04/16 18:41 (dev-master)
License
Links
Downloads
10

Comments
comments powered by Disqus

Get Table Name

This package provides a way to get statically table name and primary key in laravel

Features

  • Implement 2 methods to retrieve table name & primary key name

Installation

To install the package, use the following command:

composer require theoLuirard/laravel-get-table-name 

Configuration

Add the trait to your model

Simply add the trait to your model definition


<?php

namespace App\Models;

use HasTreeStructure;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    use HasTreeStructure;
}

Usage

To get the table name statically

MyModel::getTableName(); // Returns "my_table_name"
MyModel::getTableName(true); // Returns "my_connection.my_table_name"

To get the primary key name statically

MyModel::getTableName(); // Returns "my_primary_key"
MyModel::getTableName(true); // Returns "my_table_name.my_primary_key"