The Blog

Laravel

Laravel

Laravel String Pluralization

John Koster
John Koster
November 30, 2016

Learn how to handle pluralization and specific numbers in Laravel's translator. Message tags can be used as comments for different plural translation messages. Laravel allows for handling specific numbers by passing them directly to the translation message. Intervals can also be used in translation messages to match a range of numbers.

Laravel

Laravel's Bcrypt Hasher

John Koster
John Koster
November 30, 2016

Learn about the Bcrypt hasher in Laravel, how to set the number of rounds for the hash calculation, and how to generate and check hashes using the make and check methods. See examples of generating hashes and checking their validity. Also, discover how to determine if a hash needs to be rehashed and how to use the Hash facade to access hasher methods.

Laravel

The Laravel Translator

John Koster
John Koster
November 30, 2016

The Translator class is responsible for handling interactions between the application and the translation systems. It implements Symfony's TranslatorInterface and provides functions to determine if a translation exists, retrieve translations with replacements, and pluralize translations. The class also allows you to set and get the current locale and fallback locale. You can access the Translator instance from the application container using the translator name.

Laravel

An Introduction To Laravel Collections

John Koster
John Koster
November 29, 2016

Learn to use the Illuminate\Support\Collection class in Laravel to manipulate data using familiar array syntax. Access and iterate through the collection using key/value pairs. Retrieve values associated with known keys and work with the underlying array using the toArray method. Be aware that array-specific functions will not work directly on a collection, but can be used on the underlying array. Use methods like get to retrieve data from the collection with the option to return a default value. Create a new collection instance by passing an array of items to the constructor, or by using the make method or the collect helper function.

Laravel

An Introduction to Laravel Message Bags

John Koster
John Koster
November 29, 2016

The Illuminate\Support\MessageBag class is a key/value storage system for storing different types of messages and specifying a format for returning them. It implements both the Illuminate\Contracts\Support\MessageProvider and Illuminate\Contracts\Support\MessageBag interfaces. The MessageProvider interface allows other classes to return MessageBag implementations. This article also provides a list of classes that extend, implement, or make use of the MessageProvider interface. Check out the rest of the articles in the series to learn more about the Laravel ErrorMessageBag component.

Laravel

An Introduction to Laravel View Error Bags

John Koster
John Koster
November 29, 2016

The Illuminate\Support\ViewErrorBag class is a container for error messages used to communicate with views and responses. When there are errors in the current request, an instance of ViewErrorBag is shared with views. The ViewErrorBag instance can be accessed using the errors name. The class provides several public methods for interacting with the error bags.

Laravel

An Introduction to Laravel's Collection Public API

John Koster
John Koster
November 29, 2016

Learn about the public API of the Collection class in this section. With 64 methods, this extensive API allows you to retrieve values, transform arrays, implement pagination, and perform simple aggregates. You'll gain a deep understanding of this powerful class, excluding methods needed for implementing PHP's ArrayAccess and IteratorAggregateinterfaces, as well as the getCachingIterator method.

Laravel

Laravel Collection Public API: all

John Koster
John Koster
November 29, 2016

The all method in Laravel allows you to retrieve the underlying array that a collection is using to store its data. This method can be useful when you need to work with the raw array data instead of the collection object. The all method preserves any nested collections within the main collection, making it easy to access and manipulate the entire data structure. If you want to convert nested collections to arrays as well, you can use the toArray method instead.

Laravel

Laravel Collection Public API: chunk

John Koster
John Koster
November 29, 2016

The chunk method in Laravel allows you to break a large collection into smaller collections. The method takes two parameters: $size, which determines the size of each new collection, and $preserveKeys, which indicates whether the new collections should retain the original array keys. By default, the newly created collections will not have the original array keys, but you can change this behavior by setting $preserveKeys to true.

Laravel

Laravel Collection Public API: collapse

John Koster
John Koster
November 29, 2016

The collapse method is used to combine all the first-level items of a collection into a new, single collection. It does not recursively collapse inner arrays. When called, it returns an instance of the Collection class. The collapse method can be particularly useful when working with nested arrays or collections.

Latest posts

That Escalated Quickly: All the New Things

The past six months or so have been incredibly busy. What started as a new article series about cust...

Read more
Troubleshooting a Statamic Illegal Offset Type Error when Viewing Collection Entries in the Control Panel

In this post I talk about how I resolved a mysterious illegal offset type error when viewing collect...

Read more
Creating Simple HTTP Redirect Routes from a Statamic Site

Generating a custom Laravel routes file from a Statamic website to redirect to a new domain.

Read more
Disabling Vite File Hashes

Disabling file hashes in Vite output can be accomplished by modifying your project's vite.config.js

Read more
Implementing a Custom Laravel Blade Precompiler for Volt and Livewire

Learn how to implement a custom component compiler for Laravel's Blade templating language in this p...

Read more
Creating a Hybrid Cache System for Statamic: Part Five

Part 5 of 6 covers implementing a cache namespace and labeling system, which we can use to target mu...

Read more