theoluirard/laravel-get-table-name

A package that adds a trait to the Laravel Model class and extends the Laravel Relation class with two new types of relations.

v1.0.3 2025-04-16 16:41 UTC

This package is auto-updated.

Last update: 2025-06-16 17:02:46 UTC


README

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"