dex / anything
It can be anything
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- illuminate/support: ^10.0||^11.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-10-29 17:13:18 UTC
README
You always need to create auxiliary tables in your database to store few records just to have good database
normalization, with anything
package this will finish.
Installation
You can install the package via composer:
composer require dex/anything
Now, you can create any virtual/logical model using Anything
model or extended it.
Belongs to relation
Suppose you have a Person
model that have a belongsTo
relation with Gender
, Race
and Religion
model, you
should have something like this for you models using 4 database tables.
class Person extends Model { protected $table = 'person'; public function gender(): BelongsTo { return $this->belongsTo(Gender::class); } public function race(): BelongsTo { return $this->belongsTo(Race::class); } public function religion(): BelongsTo { return $this->belongsTo(Religion::class); } } class Gender extends Model { protected $table = 'gender'; } class Race extends Model { protected $table = 'race'; } class Religion extends Model { protected $table = 'religion'; }
For each model you will have a database table.
But using Anything
model you will have just 2 database tables.
class Person extends Model { protected $table = 'person'; public function gender(): BelongsTo { return $this->belongsTo(Gender::class); } public function race(): BelongsTo { return $this->belongsTo(Race::class); } public function religion(): BelongsTo { return $this->belongsTo(Religion::class); } } class Gender extends Anything { } class Race extends Anything { } class Religion extends Anything { }
And you still have access through Eloquent relationships normally
$person = Person::factory()->create(); $person->gender->label; // Ex.: Female $person->race->label; // Ex.: Black $person->religion->label; // Ex.: Atheist
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.