vicenterusso / laravel-table-structure
This is my package TableStructure
v0.0.1
2021-04-20 11:59 UTC
Requires
- php: ^7.2|^8.0
- illuminate/contracts: ^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.9
- vimeo/psalm: ^4.4
This package is auto-updated.
Last update: 2024-10-20 23:31:17 UTC
README
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:
composer require vicenterusso/laravel_table_structure
You can publish the config file with:
php artisan vendor:publish --provider="VRusso\TableStructure\TableStructureServiceProvider" --tag="laravel_table_structure-config"
This is the contents of the published config file:
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
# 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
License
The MIT License (MIT). Please see License File for more information.