Download the PHP package larastash/options without Composer

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

🧰 Laravel Options

The Options class provides a convenient way to interact with option values in a Laravel application.

It allows you to set, get, remove, and check the existence of options. The class also includes methods to manage previously retrieved option values and provides a query builder for the option model.

Requirements

To support JSON fields in a database, ensure that your chosen database meets the following requirements:

Installation

You can install it using Composer:

Run database migration:

✨ Get to work, you're done!

Usage

To use the Options class, make sure to import it into your PHP file:

Or get Larastash\Options\Option singletone class from app container:

Also, you can use the option() helper.

Set an Option

You can set the value of an option using the set method:

This method will update the value of the option with the specified key. If the option doesn't exist, it will be created.

You can also specify a time-to-live (TTL) for the option. The TTL determines how long the option will be cached. If a TTL is specified, the option will be stored in the cache in addition to being persisted in the database:

Get an Option

To retrieve the value of an option, use the get() method:

You can also specify a default value to return if the option is not found:

If a TTL is specified and the option is found in the cache, the cached value will be returned. Otherwise, the option will be retrieved from the database.

If TTL is not null, then get the fresh value from the database, ignoring the cached value.

Remove an Option

You can remove an option using the remove method:

This will delete the option from the database and remove it from the cache, if it exists.

Check if an Option Exists

You can check if an option exists using the exists() method:

The exists method returns true if the option with the specified key exists in the database; otherwise, it returns false.

Get All Option Values

To retrieve all option values, you can use the all method:

The all method returns a Illuminate\Database\Eloquent\Collection of all option values.

Querying the Option Model

You can access the query builder of the option model using the query method:

The query method returns an instance of the Illuminate\Database\Eloquent\Builder class that can be used to build custom queries on the option model.

Advanced Usage

If you need more advanced querying capabilities, you can use the query() method to get a query builder instance for the option model. This allows you to perform complex database queries on the option model:

This example retrieves all options whose keys start with a specific prefix.

Helpers

option()

The option() function provides a convenient way to interact with option values in a Laravel application. It acts as a wrapper around the Options class methods and simplifies the retrieval and setting of options.

Parameters:

Return Value:

The function returns the value of the option with the specified key if a key is provided.

If an array is provided, it sets the value of the option with the specified key.

If no arguments are provided, it returns an instance of the Option class.

Usage Examples:

Get an Option:

This retrieves the value of the option with the specified key. If the option does not exist, it returns the provided default value.

Set an Option:

This sets the value of the option with the specified key. If the option does not exist, it will be created.

Access the Option class:

This returns an instance of the Option class, allowing you to perform advanced operations.

Testing

Contributing

If you find any issues or have suggestions for improvement, please feel free to contribute by creating a pull request or submitting an issue.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of options with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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 larastash/options contains the following files

Loading the files please wait ....