The Blog

Laravel

Laravel

Laravel URL Helper Function: secure_url

John Koster
John Koster
November 21, 2016

The secure_url helper function in Laravel generates secure, fully qualified URLs to a given $path. It can also include additional data as query parameters. This function internally returns the value of the url helper function. An example usage is demonstrated, showing how to generate URLs with and without query parameters.

Laravel

Laravel URL Helper Function: url

John Koster
John Koster
November 21, 2016

The url helper function in Laravel is used to generate URLs to a given path or return an instance of the UrlGenerator implementation. It can be called without any arguments to return the UrlGenerator instance or with arguments to generate a URL with optional parameters. Secure URLs can also be generated by passing true as an argument.

Laravel

A Comparison of the abort, abort_if, and abort_unless Helper Functions

John Koster
John Koster
November 20, 2016

This article provides a comparison of three Laravel application helper functions: abort, abort_if, and abort_unless. While all three functions can cause the application's execution to stop, abort_if and abort_unless offer more readable and concise code. The article includes examples demonstrating the differences in usage. The choice between the functions depends on personal preference and the semantics of the variable names.

Laravel

Considerations of Using the array_sort Laravel Helper Function

John Koster
John Koster
November 20, 2016

Learn how to use the array_sort function in Laravel, as discussed in our latest blog article. This function internally creates a new instance of the \Illuminate\Support\Collection class and then sorts it using the given callback. However, it is better to use the collection's sortBy method directly instead of creating a new object every time. Check out the article to find out more.

Laravel

Laravel Application Helper: abort_if

John Koster
John Koster
November 20, 2016

The abort_if helper function in Laravel is used to abort the execution of the application based on a given condition. It throws an exception if the $boolean parameter evaluates to true. This function is commonly used to check for authorization before continuing with the application's execution. An example usage is provided in the code snippet, where the function will abort the execution if the $user object does not have the admin property set to true.

Laravel

Laravel Application Helper: abort_unless

John Koster
John Koster
November 20, 2016

The abort_unless helper function in Laravel is used to check a condition and abort the execution of the application if the condition evaluates to false. It throws an instance of Symfony\Component\HttpKernel\Exception\HttpException with the specified error code, message, and optional headers. In the provided example, if the value of $user->admin is not true, the code will abort with a 401 error code.

Laravel

Laravel Application Helper: app

John Koster
John Koster
November 20, 2016

The app function in Laravel gives you access to the Illuminate\Container\Container instance. It is a singleton, which means multiple calls to app() will return the same instance. You can also use app to resolve registered dependencies from the Container instance. For example, to get an instance of the Illuminate\Auth\AuthManager class, you can use app('auth').

Laravel

Laravel Application Helper: app_path

John Koster
John Koster
November 20, 2016

The app_path function in Laravel returns the full path to the application directory. It can also be used to build paths relative to the application directory. However, it does not automatically add a trailing forward slash to the path. To add a trailing forward slash, the str_finish function can be used.

Laravel

Laravel Application Helper: auth

John Koster
John Koster
November 20, 2016

The auth helper function in Laravel is used to retrieve an instance of Illuminate\Contracts\Auth\Factory, which is responsible for handling authentication. It is an alternative to using the Auth facade. If no arguments are provided, auth() returns the currently logged in user. You can also specify a custom authentication guard by passing the guard name as an argument. When $guard is set to null, the AuthManager instance uses the default guard specified in the configuration file.

Laravel

Laravel Application Helper: base_path

John Koster
John Koster
November 20, 2016

The base_path function in Laravel retrieves the path to the directory where the application is installed. It can also be used to construct paths relative to the base path. In the given example, the base_path function is used to retrieve the base path and construct paths for the app and public directories. Note that the function does not automatically add a trailing slash to the path.

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