Download the PHP package laragear/capstone without Composer

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

Capstone

Latest Version on Packagist Latest stable test run Codecov Coverage Maintainability Sonarcloud Status Laravel Octane Compatibility

Limit the number of model records by amount or date.

Become a sponsor

Your support allows me to keep this package free, up-to-date and maintainable.

Requirements

Installation

You can install the package via Composer.

How this works?

This library can limit how many models can be persisted in a table. The only requisite is a primary key, and that these models share a particular column value.

For example, imagine a Post model having Drafts. To limit the amount of drafts present in the database for that post, this library does it automatically using the Laragear\Capstone\HasCap trait. By default, it uses a limit of 5. It only requires a column to group the drafts to keep, which would be post_id.

Set up

Find the Eloquent Model you want to limit, add the Laragear\Capstone\HasCap trait with the keep() method.

The next step is to configure which column to group the models to keep, otherwise the whole table would be affected. The keep() method receives a Laragear\Capstone\Keep instance you can use to point out the column (or columns) to group the models.

For example, we can use the post_id to group the drafts for a particular post with the same() method and the name of the column, which will exclude drafts with different post_id from the operation.

You may also set more than one column to match more records in the database.

Alternatively, you may use a callback that modifies the query to group the records to limit. The callback receives the Illuminate\Database\Eloquent\Builder instance you can adjust to your liking.

[!IMPORTANT]

The query is using only to group the records that will be kept or deleted, not to apply limits.

Amount limit

By default, the records are limited by 5. Each time a new record is inserted into the database, the oldest (by their primary key) is deleted. You may change the amount using the by() method.

You also disable the limit by setting it to 0 (zero) or using all(). In that case, you should complement this with a time limit.

[!TIP]

You can combine both by() and after() to limit records by amount and time, respectively.

Time limit

You can also limit the records to keep by a relative date in the past using the after() method, which accepts a DateTimeInterface like a Carbon instance or a string to be parsed through strtotime.

By default, it uses the model creation timestamp to pick which records should be kept. You may use a different column by setting its name a second parameter.

[!TIP]

You can combine both by() and after() to limit records by amount and time, respectively.

Ordering

When the models to keep are queried to exclude them from the deletion, these are ordered by their primary key in descending order. If your models have unordered primary keys, like UUID v4, or strings, you may change the query order by their creation timestamp using latest() and oldest().

Both methods also accept the column to sort the records if these don't have a creation timestamp, or you need to sort them using another column.

Force delete

Records that are not kept will be removed using the delete() query method. If your model uses soft deletes, you may remove it completely from the databases using forceDelete() method.

In case you require to issue a condition for force deletion, you can use a variable that evaluates to true or false, or a callback that receives the model and returns the result of the condition.

Cancelling deletion

If you require to disable deleting out-of-bounds records, then you can use deleteWhen() and deleteUnless() with a condition or callback that evaluates to truthy or falsy, respectively, as long it's not null.

Laravel Octane compatibility

There should be no problems using this package with Laravel Octane.

Security

If you discover any security-related issues, issue a Security Advisor

License

This specific package version is licensed under the terms of the MIT License, at the time of publishing.

Laravel is a Trademark of Taylor Otwell. Copyright © 2011–2026 Laravel LLC.


All versions of capstone with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/database Version 12.*|13.*
illuminate/support Version 12.*|13.*
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 laragear/capstone contains the following files

Loading the files please wait ...