Download the PHP package weblogin/laravel-lookup without Composer

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

⚠️ This Package was originally created on Laravel 7 because it didn't offer this kind of feature. Since Laravel 9 we can use Enum Eloquent attribute casting, in most cases they can do the same as Laravel-Lookup so we recommend giving them a try instead of our package.

Laravel Lookup

Laravel Lookup helps to have a place to store static data of your Laravel application with little sugar added to it and Eloquent casts to easily use them in your Laravel models. Useful when you don't want to create database tables for every little things, think of it as static model.

Imagine you have a Car model with an attribute engine that can have the value gasoline, electric or hybrid. Creating a model and a database table can be overkill for this simple key/value data.

In the past we used language files to store this but would end up having to deal with a simple array when calling Lang::get('car.engines'). It felt weird and not realy DRY when needing to add some reusable logic for these data. The main goal was having one stable source to get this data and be able to have some flexibility in it.

With a lookup object (other call it Value object) you'll be able to have a collection containing real objects. It lets you use the power of Laravel collection to easily populate a dropdown select, add form validation, populate factories, etc and with Laravel custom cast we can access them like a real model relation for a nice code readability.

Installation

You can install the package via composer :

Usage of Lookup

With our Car model example that have a engine attribute we could create a CarEngineLookup in App/Models/Lookups. It should look like bellow, with a getItems() method returning an array, each item of the array should contain the same keys and they need to be declared as public in the class :

Because getItems() have to return a simple array you can use this package with translation as you like, for example :

A Lookup object can be used as a collection by calling any static method on it, so you can do :

The find() method should be used to find one or multiple lookups in the collection (return null if nothing found) :

Populating random values inside model factories

Populating select input and Validation :

Because a Lookup is an object you can add attributes (they need to be declared in the class and in the getItems() method) and helper methods on the class :

Usage of Casts

There are 2 casts in this package, both of them uses the primary key of the lookup object to get and set values from the database (go to the Configuration section to read more about the primary key) :

LookupCast

Still with our Car model that have an engine attribute, the model would look like this to use the CarEngineLookup stored in App/Models/Lookups:

In your code you can now access the engine attribute object :

Note: If the key is not in the collection the attribute equals to NULL.

LookupCollectionCast

Now our Car model needs a options attribute that should store multiple options coming from a lookup CarOptionLookup :

In your code you can now access the options attribute that return a collection :

Note: If the keys are not in the collection the attribute equals to NULL.

Search in database

For LookupCast you can do a simple where() query, nothing special :

For LookupCollectionCast, the values are stored in the database as JSON so you can use whereJsonContains() but if you pass multiple keys this method search for the presence of each key. To search the presence of at least one key the package include a new database query method whereInLookupCollection($column, $values) :

Configuration

Database column type

Set database column that will store the value according to your Lookup usage, VARCHAR for single value and JSON for multiple values.

Primary key

By default a Lookup needs to have key attribute defined for each item and it needs to be unique (it can by a string or int). It's used to retrieve the object from the collection. But you can override this primary key by adding a $primaryKeyName attribute to the class :

License

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


All versions of laravel-lookup with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/contracts Version ^7.0|^8.0|^9.0|^10.0
illuminate/database Version ^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.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 weblogin/laravel-lookup contains the following files

Loading the files please wait ....