The blog

Laravel 5: Accessing the Authentication Manager With auth

Apr 14, 2018

The auth helper function in Laravel allows you to quickly access the authentication features of the framework. It can be used instead of the Auth facade to retrieve the currently logged in user. By default, the auth function returns an instance of Illuminate\Contracts\Auth\Factory, which is an instance of Illuminate\Auth\AuthManager. Custom authentication guards can also be accessed by providing an argument for the $guard parameter. When no argument is supplied, the AuthManager instance will use the default web guard.
Laravel 5: Accessing the Cache System With cache

Apr 14, 2018

The cache helper function in Laravel allows you to access the cache store, retrieve existing items, and store new items in the cache. By using different argument combinations, you can control its behavior. You can easily check if an item exists in the cache using cache()->has('key'). You can also retrieve an item from the cache, and if it doesn't exist, you can specify a default value to be returned instead. Additionally, you can set new cache values with an expiration time.
Laravel 5: Accessing the Logging Features With logger

Apr 14, 2018

The logger helper function in Laravel can be used to retrieve the logger instance from the Service Container or to log debug messages within your application. It eliminates the need to inject dependencies or use the Illuminate\Support\Facades\Log facade. The function signature includes parameters for the message and context, where the message can be written to log files and the context can be an array of any element type. Multiple examples of using the logger function are provided, along with the resulting log messages in the log files. Additionally, alternative methods for logging debug messages are shown, all of which are equivalent.
Laravel 5: Accessing the Service Container With app

Apr 14, 2018

The app function in Laravel gives you access to the singleton Illuminate\Container\Container instance. It can be used to resolve registered dependencies from the Service Container. For example, to get an instance of Illuminate\Auth\AuthManager, you can use app('auth') or app()->make('auth').
Laravel 5: Accessing Validation Features With validator

Apr 14, 2018

The validator helper function is a versatile function that allows you to validate data. It can be used without any arguments to return an instance of the validation factory. You can also use it with arguments, similar to the Validator facade, to perform validation on input data. Overall, the validator helper function is a convenient way to perform data validation in Laravel.
Laravel 5: Attempt an Error-Prone Operation a Number of Times With retry

Apr 14, 2018

Learn how to use the retry helper function in PHP to attempt an operation that may throw exceptions multiple times. The retry function will retry the operation a specified number of times and can also introduce a delay between attempts. If the operation still fails after the specified attempts, an exception will be thrown.
Laravel 5: Comparing abort, abort_if, and abort_unless Helper Functions

Apr 14, 2018

The abort, abort_if, and abort_unless functions can be used to stop the execution of an application. They all achieve the same result, but abort_if and abort_unless have the advantage of being more readable and requiring less code. In the provided examples, these functions are used to check if a user has admin privileges and abort the execution if not. The choice of which function to use depends on personal preference and the semantics of the variable names.
Laravel 5: Conditionally Throwing Exceptions With throw_if

Apr 14, 2018

The throw_if function allows you to throw an exception when a given boolean value is true. You can pass additional parameters to the exception's constructor. In this example, an exception will be thrown if the supplied value is equal to 10.
Laravel 5: Conditionally Throwing Exceptions With throw_unless

Apr 14, 2018

The throw_unless helper function allows you to easily throw an exception if a condition evaluates to false. It takes in a boolean value and an exception class as parameters and throws a new instance of the exception if the boolean value is false. Parameters can also be passed to the exception's constructor if needed. An example use case is shown, where an exception is thrown if the supplied value is equal to 10.
Laravel 5: Conditionally Throwing HTTP Exceptions With abort_if

Apr 14, 2018

The abort_if helper function in Laravel is used to abort execution if a certain condition is met. It takes in a boolean argument and will abort if the argument supplied evaluates to true. This function is useful for performing a conditional check and calling the abort function in one line. An example use case would be to check if a user has admin privileges and abort with a 401 error code if not.
Laravel 5: Conditionally Throwing HTTP Exceptions With abort_unless

Apr 14, 2018

The abort_unless helper function is used to perform a conditional check and abort the execution of the application if the condition evaluates to false. This function allows you to combine the conditional check and the abort function in one line of code. An example use case is when you want to verify if a user has admin privileges and abort the execution with a 401 error code if they do not. The abort_unless function provides a clear and concise way to express this intent in your code.
Laravel 5: Creating Eloquent Models for Testing With factory

Apr 14, 2018

The factory function is used to create Eloquent models, especially for testing purposes. It can be called in different ways, such as returning an instance of a model, multiple instances of a model, or with modifications bound to a specific description.
Laravel 5: Decrypting Strings With decrypt

Apr 14, 2018

The decrypt helper function is used to decrypt a given value. It resolves the configured "Illuminate\\Contracts\\Encryption\\Encrypter" implementation from the Service Container and calls the decrypt method on the Encrypter instance. You can use the decrypt helper function or the Crypt facade to decrypt the value. Alternatively, you can resolve an instance from the Service Container using app('encrypter') or resolve('encrypter') and call the decrypt method on it.
Laravel 5: Dispatching Queued Jobs Immediately With dispatch_now

Apr 14, 2018

The dispatch_now function in PHP allows you to process a job immediately within the current PHP process, without going through the job queue. It's useful for executing a job's task right away. You can use it by creating a job and then invoking dispatch_now with the job instance, as demonstrated in the provided example.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.