Monday, November 28, 2022
HomePHPConnect Time-sliced Metadata to Eloquent Fashions

Connect Time-sliced Metadata to Eloquent Fashions


Laravel Multiplex is a Laravel bundle to connect time-sliced metadata to Eloquent fashions. With the v1.0 launch close to, listed below are the primary options:

  • Metadata is saved in variations, together with the power to schedule metadata for the long run
  • Fluent syntax
  • East to attempt extending your mannequin with versionable metadata with out touching unique columns
  • Sort conversion system
  • Configurable

Listed below are a number of primary examples of how this bundle appears to be like working with a mannequin:

1$publish = AppModelsPost::first();

2 

3// Set meta fluently for any key – `likes` is not any column of `Put up`.

4$publish->likes = 24;

5 

6// Or use the `setMeta` methodology.

7$publish->setMeta('likes', 24);

8 

9// Set a number of values

10$mannequin->setMeta([

11 'hide' => true,

12 'color' => '#000',

13 'likes' => 24,

14]);

15 

16// You might also schedule adjustments, for instance, change the meta in 2 years:

17$publish->setMetaAt('likes', 6000, '+2 years');

It’s also possible to restrict which meta keys are allowed on a mannequin with a $metaKeys property:

1class Put up extends Mannequin

2{

3 use HasMeta;

4 

5 protected array $metaKeys = [

6 'color',

7 'hide',

8 ];

9 

10 // You should use typecast array keys

11 protected array $metaKeys = [

12 'foo',

13 'count' => 'integer',

14 'color' => 'string',

15 'hide' => 'boolean',

16 ];

17 

18}

Once you arrange this bundle, learn the efficiency part to keep away from N+1 queries. To be taught extra about this bundle and get full set up directions, take a look at the laravel-metadata on GitHub.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments