https://github.com/vicenterusso/laravel-table-structure
Get table field information adding only a trait to the model. Supports caching
https://github.com/vicenterusso/laravel-table-structure
database laravel schema table
Last synced: 6 months ago
JSON representation
Get table field information adding only a trait to the model. Supports caching
- Host: GitHub
- URL: https://github.com/vicenterusso/laravel-table-structure
- Owner: vicenterusso
- License: mit
- Created: 2021-04-19T23:22:12.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T16:04:43.000Z (about 5 years ago)
- Last Synced: 2025-10-25T16:54:16.701Z (9 months ago)
- Topics: database, laravel, schema, table
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Table Structure
[](https://packagist.org/packages/vicenterusso/laravel-table-structure)
[](https://github.com/vicenterusso/laravel-table-structure/actions?query=workflow%3Arun-tests+branch%3Amaster)
[](https://github.com/vicenterusso/laravel-table-structure/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amaster)
This package helps you to get information about your table fields adding only a `trait` to your model. You can also optionally cache the results.
## Installation
You can install the package via composer:
```bash
composer require vicenterusso/laravel_table_structure
```
You can publish the config file with:
```bash
php artisan vendor:publish --provider="VRusso\TableStructure\TableStructureServiceProvider" --tag="laravel_table_structure-config"
```
This is the contents of the published config file:
```php
return [
/*
|--------------------------------------------------------------------------
| Enable Cache
|--------------------------------------------------------------------------
|
| Enable or disable usage of cache for Schema queries.
|
*/
'use_cache' => false,
/*
|--------------------------------------------------------------------------
| Cache Prefix
|--------------------------------------------------------------------------
|
| Custom prefix for cache keys. Avoid empty values
|
*/
'cache_prefix' => env('TABLE_STRUCT_PREFIX', 'TABLE_STRUCT'),
];
```
## Usage
Insert the following trait to any model, and you can retrieve all info about the table fields
```php
# Add trait to model
use \VRusso\TableStructure\Traits\FieldsInfo;
# Call it anywhere
User::hasField('username');
//true/false
User::getAllFields();
//['username', 'password', ...]
User::getAllFieldsWithTypes();
//[
// [
// 'field' => 'username',
// 'type' => 'string'
// ],
// (...)
//]
User::getAllFieldsWithTypeOf('integer');
//['id', ...]
```
## Credits
- [Vicente Russo](https://github.com/vicenterusso)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.