Download the PHP package proai/laravel-struct without Composer

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

Laravel Struct

Latest Stable Version Total Downloads Latest Unstable Version License

A struct is a collection of typed variables. Structs are a well known datatype in other programming languages, but unfortunately not natively part of PHP yet. This package aims to bring structs to PHP and in particular to Laravel.

Installation

You can install the package via composer:

Please note that you need at least PHP 7.4 and Laravel 8 for this package.

Usage

The package uses named properties, which were introduced in PHP 7.4, to define a struct:

You can use all primitive types like string, bool, float, int, but also you can type a property as an object. The object can also be another struct, which enables you to nest structs (like GeoLocation above).

Structs are instantiated by using an array of values:

Properties that are typed as objects will be converted to these objects on instantiation. Thus in the example above an object of App\Structs\GeoLocation will be created for the $geo_location property.

Properties can be accessed normally:

Hint: Snake cased properties are used to mimic the behaviour of Eloquent attributes.

Attribute Casting

You can use attribute casting with structs in your Eloquent models:

In order to make this work you need to define a json column of the specified key, so in this case address.

Alternatively you can use the composed struct caster by adding the argument composed to compose a struct from multiple columns:

The column names must start with the specified key followed by an underscore and the property name. This also works with nested structs. For the example above we would need the following columns:

Finally you can also write your own custom caster by overwriting the castUsing method of the struct like described in the Laravel docs.

Collections

Sometimes you need an array of structs. For this purpose you can define a struct collection. The struct collection class is inherited from the Laravel collection class, so you can use all methods of a Laravel collection.

By the way, attribute casting also works with struct collections for json columns.

Support

Bugs and feature requests are tracked on GitHub.

License

This package is released under the MIT License.


All versions of laravel-struct with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/database Version ^10.0||^11.0
illuminate/support Version ^10.0||^11.0
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 proai/laravel-struct contains the following files

Loading the files please wait ....