Download the PHP package spatie/laravel-schemaless-attributes without Composer

On this page you can find all versions of the php package spatie/laravel-schemaless-attributes. 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 laravel-schemaless-attributes

Add schemaless attributes to Eloquent models

Latest Version on Packagist GitHub Workflow Status Total Downloads

Wouldn't it be cool if you could have a bit of the spirit of NoSQL available in Eloquent? This package does just that. It provides a trait that when applied on a model, allows you to store arbitrary values in a single JSON column.

Here are a few examples. We're using the extra_attributes column here, but you can name it whatever you want.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Requirements

This package requires a database with support for json columns like MySQL 5.7 or higher.

Installation

For Laravel versions 6 & 7 or PHP 7, use version 1.x of this package.

You can install the package via composer:

The schemaless attributes will be stored in a json column on the table of your model. Let's add that column and prepare the model.

Adding the column where the schemaless attributes will be stored

Add a migration for all models where you want to add schemaless attributes to. You should use schemalessAttributes method on Blueprint to add a column. The argument you give to schemalessAttributes is the column name that will be added. You can use any name you'd like. You're also free to add as many schemaless attribute columns to your table as you want. In all examples of this readme we'll use a single column named extra_attributes.

Preparing the model

In order to work with the schemaless attributes you'll need to add a custom cast and a scope on your model. Here's an example of what you need to add if you've chosen extra_attributes as your column name.

If you need support for multiple schemaless columns on a single model, you should use SchemalessAttributesTrait trait. Here's an example of what you need to add if you've chosen extra_attributes, other_extra_attributes as your column names.

If you want to reuse this behaviour across multiple models you could opt to put the function in a trait of your own. Here's what that trait could look like:

Usage

Getting and setting schemaless attributes

This is the easiest way to get and set schemaless attributes:

Alternatively you can use an array approach:

You can replace all existing schemaless attributes by assigning an array to it.

You can also opt to use get and set. The methods have support for dot notation.

You can also pass a default value to the get method.

Persisting schemaless attributes

To persist schemaless attributes you should, just like you do for normal attributes, call save() on the model.

Retrieving models with specific schemaless attributes

Here's how you can use the provided modelScope.

If you only want to search on a single custom attribute, you can use the modelScope like this

Also, if you only want to search on a single custom attribute with a custom operator, you can use the modelScope like this

If you only want to search on a nested custom attribute, you can use the modelScope like this

Testing

First create a MySQL database named laravel_schemaless_attributes. After that you can run the tests with:

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.


All versions of laravel-schemaless-attributes with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/contracts Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/database Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0|^11.0
spatie/laravel-package-tools Version ^1.4.3
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 spatie/laravel-schemaless-attributes contains the following files

Loading the files please wait ....