Download the PHP package langleyfoxall/helpers-laravel without Composer

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

Helpers Laravel

Packagist

A repository of Laravel specific helper classes to help standardise work. API helpers, converters etc.

Installation

The Langley Foxall Helpers Laravel package can be easily installed using Composer. Just run the following command from the root of your project.

If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.

Helpers

Models

The Eloquent Models.

Methods

All methods can be called statically.

all

Get a Collection of all models.

Example Usage
Key Details
Parameters None
Throws None
Returns Collection
utf8EncodeModel

Encodes attribute values of a single model to UTF-8, and returns the model.

Example Usage
Key Details
Parameters Model
Throws None
Returns Model
utf8EncodeModels

Encodes attribute values of mutliple models to UTF-8, and returns a collection of model.

Example Usage
Key Details
Parameters A Collection of Models
Throws None
Returns A Collection of Models
getColumns

Get an Array of the database columns for a given model.

Example Usage
Key Details
Parameters Model
Throws None
Returns Array
getNextId

Get the next auto incremented ID for a model.

Example Usage
Key Details
Parameters Model
Throws Exception
Returns Integer
areRelated

Check if an unspecificed number of models are related to each other.

Example Usage

If an instance of Model is passed, then areRelated will attempt to get a plural then singular method from the model that can then be used by the previous model in the sequence to confirm that they are related. If an array is passed, it expects the first element to be an instance of Model and the second to be a string which is the relationship method

A NotRelatedException is also provided to be used in an application.

Key Details
Parameters Mutliple Models or Mutliple Array
Throws Exception or InvalidArgumentException
Returns Boolean
randomByWeightedValue

Takes a collection of Model's and returns one based upon a weighted column. It can also take a maxCap to simulate higher odds.

It should be noted when passing a maxCap you should pass in a desired return value if none of the items in the models list were hit.

Example Usage
Key Details
Parameters A Collection of Models or a string representation of a Model, column, maxCap = null, ifLose = null
Throws None
Returns Model or an object

IsRelatedTo

The Models helper.

Methods

isRelatedTo

Check if a single model is related to the parent model.

Example usage
Key Details
Parameters Model or Array
Returns Boolean

Enum

The Enum helper is a trait that provides helpers for dealing with enum classes.

Methods

all

Return an array of all values.

Example usage
Key Details
Parameters
Returns Array
valid

Check if a provided value is a valid value of the enum class.

Example usage
Key Details
Parameters String
Returns Boolean

ApiResponse

The ApiResponse helper standardizes an API response. Always containing the same fields:

Key Type Description
status Integer status is used for accessibility when the response cannot access the HTTP client, such as axios
success Boolean success is a boolean to signify that an operation was successful or not
error NULL, String or Array error is used to describe errors or warnings that have happened during the operation
data NULL or Array data should contain the main resource information
meta NULL or Array meta should contain extra resource information, such as other endpoints that can be used with the current resource

The here.

After building up the response, before returning it from a Controller, you must call json.

Methods

success

Create a successful response instance.

Example Usage

None of the parameters are required.

Key Details
Parameters data, meta, status
Returns ApiResponse
error

Create a unsuccessful response instance.

Example Usage

None of the parameters are required.

Key Details
Parameters error, status
Returns ApiResponse
data

Set the data to be returned in the response.

Example Usage

None of the parameters are required.

Key Details
Parameters NULL or Array
Returns ApiResponse
meta

Set the meta to be returned in the response.

Example Usage

None of the parameters are required.

Key Details
Parameters NULL or Array
Returns ApiResponse
status

Set the response status code.

Example Usage
Key Details
Parameters Integer
Returns ApiResponse
json

Get the JSON response object

Example Usage
Key Details
Parameters None
Returns JsonResponse
cache

Cache the current ApiResponse data for use in a later request. By default if the cache currently has data in it the data will not be overwritten. Using forceOverwrite it can be overwritten, this defaults to false. cache must be called after data is set.

Example Usage

lifespan accepts an Integer value for the lifespan in minutes or a Carbon time when the cache will be cleared. cache must be an instantiated ResponseCache.

Key Details
Parameters lifespan, cache, forceOverwrite (Optional)
Returns ApiResponse

Response

The expecting JSON or not and return the right response.

Key Type Description
request Request request is used when it comes to deciding which response to return to the client
type String type is a string, "success" or "error", which will determine which API Response is returned
message NULL, String or String message is used for a redirect back with a session variable (web) or an error message (API)
data NULL or Array data should contain the main resource information
meta NULL or Array meta should contain extra resource information, such as other endpoints that can be used with the current resource
status Integer status is used for accessibility when the response cannot access the HTTP client, such as axios
uri String uri is used when wanting to redirect rather than back with a web response

Methods

None of the following methods can be called statically. When instansiating a new instance of Response a Request object is required.

success

Create a successful response.

Example Usage

None of the parameters are required.

Key Details
Parameters message, data, meta, status
Returns Response
error

Create a unsuccessful response.

Example Usage

None of the parameters are required.

Key Details
Parameters message, status
Returns Response
type

Set the response type. While error and success are not aggressively checked the type will default to success if not error.

Example Usage
Key Details
Parameters type
Returns Response
message

Set the message to be displayed if an error occurs or a back is triggered.

Example Usage
Key Details
Parameters message
Returns Response
data

Set the data to be returned in an successful ApiResponse.

Example Usage

None of the parameters are required.

Key Details
Parameters data
Returns Response
meta

Set the meta to be returned in an successful ApiResponse.

Example Usage

None of the parameters are required.

Key Details
Parameters meta
Returns Response
status

Set the status to be returned in an ApiResponse. This will be overwritten if called before success or error.

Example Usage
Key Details
Parameters status
Returns Response
redirect

Set the redirect URI to be called rather than redirecting back.

Example Usage

None of the parameters are required.

Key Details
Parameters uri
Returns Response
end

Return the expected response.

Example Usage
Key Details
Parameters None
Returns RedirectResponse or JsonResponse

ResponseCache

The ResponseCache helper simplifies caching API Responses taking into account differing request parameters and user accounts. Unique caches are generated based on the request route, method, parameters and user.

Key Type Description
request Request The request that the cache will be for.
userSpecific Boolean userSpecific specifies if the response is cached for individual users or if all users share one cache. Important: Misuse of userSpecific can lead to massive inefficiencies and security flaws. If a response is the same for any user userSpecific should be set to false so that a new cache is not created for every user. If a response contains data pertaining to that user userSpecific should be set to true so that users do not receive someone else's cached data.
excludeParams (Optional) NULL or Array Since request parameters are likely to change the data generated a seperate cache is generated for different sets of parameters so that the correct data is returned. However some parameters do not change the data generated so a new cache does not need to be generated when they change. Adding these parameters to excludeParams will mean that they are ignored.

Methods

None of the following methods can be called statically.

hasData

Returns if the current cache has any data.

Example Usage
Key Details
Parameters None
Returns Boolean
getData

Returns the data currently in the cache, returns null if empty.

Example Usage
Key Details
Parameters None
Returns Mixed
cacheData

Saves data to the cache. Any data currently in the cache will be overwritten/

Example Usage

data can be any serializable data, lifespan can be minutes as an Integer or a Carbon time that the cache will expire at.

Key Details
Parameters data, lifespan
Returns None
getKey

Returns the unique key for the cache generated based on the request path, method, parameters and user.

Example Usage
Key Details
Parameters None
Returns String
clear

Clears the data for the given cache.

Example Usage
Key Details
Parameters None
Returns None

Usage with ApiResponse

A cache can be created from anApiResponse automatically by using the cache function on it. It will only cache new data if the cache does not contain data. See documentation here.

Example Usage

IdentifiedByUUID

The IdentifiedByUUID trait allows you to easily use V4 UUIDs over incrementing primary keys.

Example Usage

Change your migrations to allow the use of a UUID.

Use the trait.

Now when the model is saved, it will automatically be populated with a V4 UUID.


All versions of helpers-laravel with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3||^8.0
illuminate/support Version >=5.0
illuminate/database Version >=5.0
illuminate/http Version >=5.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 langleyfoxall/helpers-laravel contains the following files

Loading the files please wait ....