Download the PHP package escolalms/model-fields without Composer

On this page you can find all versions of the php package escolalms/model-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package model-fields

Model Fields

swagger codecov phpunit downloads downloads downloads Maintainability Test Coverage Mutation testing badge

What does it do

This package allows you to add unlimited extra primitive fields to any model.

Types of fields that can be user

Details documentation is provided as an example

Installing

Database

The package allows to add additional fields by creating special meta description values that are saved in database.

Next to metadata descriptions there are values that works with the meta description.

Below are examples of how matadata and values are stored in database

model_fields_metadata table sample rows

id created_at updated_at name type rules extra default class_type visibility
2147 2022-03-03 12:10:05 2022-03-03 12:10:05 description text ["required","string","max:255"] NULL lorem ipsum EscolaLms\ModelFields\Tests\Models\User 1
2148 2022-03-03 12:10:05 2022-03-03 12:10:05 interested_in_tests boolean ["required","boolean"] NULL 1 EscolaLms\ModelFields\Tests\Models\User 1
2149 2022-03-03 12:10:05 2022-03-03 12:10:05 title varchar ["required","string","max:255"] NULL EscolaLms\ModelFields\Tests\Models\User 1
2150 2022-03-03 12:10:05 2022-03-03 12:10:05 consents json ["required","json"] NULL [] EscolaLms\ModelFields\Tests\Models\User 1
2151 2022-03-03 12:10:05 2022-03-03 12:10:05 extra_points number ["required","integer"] NULL 123 EscolaLms\ModelFields\Tests\Models\User 1
2153 2022-03-03 12:11:05 2022-03-03 12:11:05 extra_description text ["required","string","max:255"] NULL lorem ipsum EscolaLms\ModelFields\Tests\Models\User 1

model_fields_values table sample rows

id created_at updated_at name value class_type class_id
1432 2022-03-03 12:17:42 2022-03-03 12:17:42 consents {"consent1":true,"consent2":false} EscolaLms\ModelFields\Tests\Models\User 1458
1433 2022-03-03 12:17:42 2022-03-03 12:17:42 extra_points 1000 EscolaLms\ModelFields\Tests\Models\User 1458
1436 2022-03-03 12:17:42 2022-03-03 12:17:42 description zzz EscolaLms\ModelFields\Tests\Models\User 1458
1438 2022-03-03 12:17:42 2022-03-03 12:17:42 interested_in_tests true EscolaLms\ModelFields\Tests\Models\User 1458

See tests folder as rows above are generated from the tests.

Example

The best documentation operates on live example so here it is.

Assuming you have User Model

In order to add extra fields to user model you would need to create new columns in user table with migration and add those fields. This is a standard way of handling this issue, but this package introduces new one.

Option 1. Extending Model

This option replaces Illuminate\Database\Eloquent\Model with EscolaLms\ModelFields\Models\Model

Option 2. Trait in Model.

This option uses EscolaLms\ModelFields\Traits\ModelFields instead of extending class;

Basically that all the steps you need to allow model to be extendable.

Defining new fields on selected Model.

Now lets create new field meta description. We'll be adding new field to user, called description which will be long text.

Interface of this method is as follows

Once new field is added you can use is as any other attribute of model

That's all, your user model is ready to be extended. You can get and set attributes as they were created standard way.

Resources and fields visibility

Using resources is simple, look at the following example

Note. In php 7.4 user array_merge instead of spread ... operator.

Look at the visibility field in example above. Package allows to define visibility of the meta fields. Here we're defining 2 fields, one is public, second admin only.

Now we can have 2 endpoints one that list user with public fields, other with visible to admin only.

Now let's see how Admin Resource would look like.

MetaFieldVisibilityEnum::ADMIN | MetaFieldVisibilityEnum::PUBLIC is a Flagged/Bitwise Enum. MetaFieldVisibilityEnum is just a proposal - you can use as many permissions as you like yet defining values you must use powers of 2, like.

Validation with FormRequest

Example below describes how to fetch validation rules from MetaField

In php 7.4 user array_merge instead of spread ... operator.

Endpoints

All the endpoints are defined in swagger.

Tests

Run ./vendor/bin/phpunit to run tests. See tests folder as it's quite good staring point as documentation appendix.

Test details codecov phpunit

Events

This package does not dispatch any events.

Listeners

This package does not listen for any events

How to use this on frontend.

Admin panel

All the endpoints defined in swagger are for admin panel.

There is native component you can use to implement this in admin panel for any model that allows extending

Example in admin panel

List of user model fields

Creating/editing model field

Front Application

See example above how to extend controllers to CRUD model fields to give model

Permissions

Permissions are defined in seeder

Roadmap. Todo. Troubleshooting.


All versions of model-fields with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
laravel/framework Version >=8.0
escolalms/core Version ^1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package escolalms/model-fields contains the following files

Loading the files please wait ....