Download the PHP package baril/orderly without Composer

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

Orderly

This package adds an orderable/sortable behavior to Eloquent models. It is inspired by the rutorika/sortable package. It was originally part of the Smoothie package.

Version compatibility

Laravel Orderly
5.6+ use Smoothie instead
6.x 1.x
7.x 1.x
8.x 2.x / 3.x
9.x 3.x
10.x 3.1+
11.x 3.2+

Setup

New install

If you're not using package discovery, register the service provider in your config/app.php file:

Add a column to your table to store the position. The default name for this column is position but you can use another name if you want (see below).

Then, use the \Baril\Orderly\Concerns\Orderable trait in your model. The position field should be guarded as it won't be filled manually.

You also need to set the $orderColumn property if you want to use another name than position:

Basic usage

You can use the following method to change the model's position (no need to save it afterwards, the method does it already):

Also, this trait:

This model will be positioned at MAX(position) + 1.

To get ordered models, use the ordered scope:

(You can cancel the effect of this scope by calling the unordered scope.)

Previous and next models can be queried using the previous and next methods:

Mass reordering

The move* methods described above are not appropriate for mass reordering because:

Example:

The sample code above will corrupt the data because you need each model to be "fresh" before you change its position. The following code, on the other hand, will work properly:

It's still not a good way to do it though, because it performs many unneeded queries. A better way to handle mass reordering is to use the saveOrder method on a collection:

That's it! Now the items' order in the collection has been applied to the position column of the database.

You can also order a collection explicitely with the setOrder method. It takes an array of ids as a parameter:

The returned collection is ordered so that the items with ids 4, 5 and 2 are at the beginning of the collection. Also, the new order is saved to the database automatically (you don't need to call saveOrder).

:warning: Note: Only the models within the collection are reordered / swapped between one another. The other rows in the table remain untouched.

You can also use the setOrder method, either statically on the model, or on a query builder.

When used like this, the setOrder method returns the number of affected rows.

Orderable groups / one-to-many relationships

Sometimes, the table's data is "grouped" by some column, and you need to order each group individually instead of having a global order. To achieve this, you just need to set the $groupColumn property:

If the group is defined by multiple columns, you can use an array:

Orderable groups can be used to handle orderable one-to-many relationships:

Orderable many-to-many relationships

If you need to order a many-to-many relationship, you will need a position column (or some other name) in the pivot table.

Have your model use the \Baril\Orderly\Concerns\HasOrderableRelationships trait:

The prototype of the belongsToManyOrderable method is similar as belongsToMany with an added 2nd parameter $orderColumn:

Now all the usual methods from the BelongsToMany class will set the proper position to attached models:

You can order the results of the relation by chaining the ordered method:

If you want the relation ordered by default, you can use the belongsToManyOrdered method in the relation definition, instead of belongsToManyOrderable.

In this case, if you occasionally want to order the related models by some other field, you will need to use the unordered scope first:

The BelongsToManyOrderable class has all the same methods as the Orderable trait, except that you will need to pass them a related $model to work with:

Note that if $model doesn't belong to the relationship, any of these methods will throw a Baril\Orderly\GroupException.

There's also a method for mass reordering:

In the example above, tags with ids $id1, $id2, $id3 will now be at the beginning of the article's tags collection. Any other tags attached to the article will come after, in the same order as before calling setOrder.

Orderable morph-to-many relationships

Similarly, the package defines a MorphToManyOrderable type of relationship. The 3rd parameter of the morphToManyOrderable method is the name of the order column (defaults to position):

Same thing with the morphedByManyOrderable method:

Artisan command

The orderly:fix-positions command will recalculate the data in the position column (eg. in case you've manually deleted rows and have "gaps").

For an orderable model:

For an orderable many-to-many relation:


All versions of orderly with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
illuminate/cache Version ^8.0|^9.0|^10.0|^11.0
illuminate/console Version ^8.0|^9.0|^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 baril/orderly contains the following files

Loading the files please wait ....