Download the PHP package ralphjsmit/laravel-helpers without Composer

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

A package containing handy helpers for your Laravel-application.

This package contains a set of handy helpers for your Laravel-application.

Installation

You can install the package via composer:

Laravel

Factories

Instead of letting your factories extend Laravel's default factories, you can let them extend the RalphJSmit\Helpers\Laravel\Factories\Factory class.

Complex factory relations with resolveRelationship()

When you have a complex relationship, you can use the resolveRelationship() method to resolve the relationship. This is useful if you want to modify the factory using a closure or something similar:

A simple example would look like this:

Pipes, pipelines & pipeable

Pipes v. pipelines

Laravel has an undocumented feature called Pipelines. Pipelines are handy for sending data through a series of functions/classes.

The pipelines in Laravel, however, have one big downside: inside every function or class, you need to call a closure to move to the next pipe in the pipeline. If you don't call that closure, the pipeline stops. Laravel Middleware is a great example of this.

However, sometimes you don't want that closure and just pass the result of the first pipe into the second pipe, meaning that the full pipeline always gets executed. This package offers a custom implementation for that, called a "pipe". You don't have a way to stop execution (use a regular pipeline instead), but you don't have to call the closure inside each pipe either.

From now on, I'll call the custom implementation of this package a "pipe" and the more advanced, regular Laravel-implementation a "pipeline".

Pipeline

You can use the pipeline() function to create a new pipeline:

To learn more about pipelines, check out this article.

Pipe

You can create a new pipe with the pipe() function:

Each of the items in the ->through() array can be one of the following:

  1. A closure or callable
  2. An invokable class (which is a callable as well)
  3. A class instance
  4. A class string

By default, the pipe will try to execute each item with via a method 'handle'. You can change that method by using the ->via() method.

At the end of each pipe, you can pass a closure to the ->then() method to do something with the result. To immedialtely return the result, you can also use the ->thenReturn() method.

`

Pipeable

This package also offers a handy trait that you can use to make your classes pipeable. If you include this trait, your classes will have the following new methods:

  1. ->pipe($callback). This method passes the object to the given closure or callable and returns the result of the executed callable.
  2. ->pipeInto($class). The pipeInto() method creates a new instance of the given class and passes the object into the constructor.
  3. ->pipeThrough($callbacks). The pipeThrough() method passes the object to the given array of closures/callables and returns the result of the executed callbacks.

All three methods are the same as the three identically named methods in the \Illuminate\Support\Collection class. For examples, see the docs for pipe(), pipeInto() and pipeThrough()` on the Laravel site.

Carbon

The package offers several handy helpers to make working with Carbon-objects more pleasant.

carbon($input = null, $timezone = null)

You can use the carbon($input, $timezone) helper to create a Carbon-object. Under the hood, this uses Carbon::parse(). Both parameters are optional.

carbonDate($input = null, $timezone = null)

You can use the carbonDate($input, $timezone) helper to create a Carbon-object and floor the day to 00:00:00. Under the hood, this uses Carbon::parse()->floorDay(). Both parameters are optional.

yesterday() and tomorrow()

You can use the tomorrow() function to create a Carbon-instance for tomorrow. Under the hood this uses now()->addDay().

You can use the yesterday() function to create a Carbon-instance for yesterday. Under the hood this uses now()->subDay().

daysOfMonth(Carbon|string $month)

You can use the daysOfMonth() function to create a Collection instance with the days of the month as numeric keys and a value of 0. Useful for creating things like graphs and the like.

Eloquent

TimeCast

Eloquent provides many nice casts, like array, date and datetime. However, Laravel doesn't provide with a time cast, for storing and casting timestamps like "08:30:00" to a Carbon instance.

The reason is probably that passing only a timestamp like "08:30:00" to Carbon assumes a Carbon instance with the current date. This might or might not be a problem for you.

In order to cast a timestring to a Carbon instance, you can set the TimeCast class as a cast. However, please be aware that this will create a carbon instance that assumes the current date.

BooleanAsTimestampCast

The BooleanAsTimestampCast cast is a handy cast that you can use to store a boolean value as a timestamp. In practice this still works the same as a normal boolean in the database. However, storing a boolean like this gives you the additional benefit of knowing when the boolean was enabled.

If the value is set to true, it will store the current timestamp in the database. If the value is set to false, it will store null in the database.

php use Illuminate\Database\Eloquent\Model; use RalphJSmit\Helpers\Laravel\Concerns\HasFactory;

class MyModel extends Model { use HasFactory; }



If you prefer or need to define the factory class yourself, you may also use the `protected $factory` property to define your factory:

## Livewire

### CanBeRefreshed trait

You may use the `CanBeRefreshed` trait to automatically register the following event:

### RegisterListeners trait

You may use the `RegisterListeners` trait to dynamically register event listeners, for example from the `mount()` or `initialized()` methods:

### RegisterMessages trait

You may use the `RegisterMessages` trait to dynamically register event listeners, for example from the `mount()` or `initialized()` methods:

## General

🐞 If you spot a bug, please submit a detailed issue and I'll try to fix it as soon as possible.

🔐 If you discover a vulnerability, please review [our security policy](../../security/policy).

🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!

🙋‍♂️ [Ralph J. Smit](https://ralphjsmit.com)

All versions of laravel-helpers with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
guzzlehttp/guzzle Version ^7.4
illuminate/contracts Version ^10.0|^11.0|^12.0
spatie/laravel-package-tools Version ^1.9.2
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 ralphjsmit/laravel-helpers contains the following files

Loading the files please wait ....