The Blog

Laravel

Laravel Application Helper Function: method_field

John Koster
John Koster
November 20, 2016

The method_field helper function in Laravel returns an instance of Illuminate\Support\HtmlString containing a hidden HTML input field. This field has the name _method and a value passed as an argument to the function. See examples with different methods: PUT, POST, GET, PATCH, DELETE. The return value is an HtmlString instance, corresponding to an HTML hidden input field.

Laravel

Laravel Application Helper Function: redirect

John Koster
John Koster
November 20, 2016

The redirect helper function in Laravel is used to redirect users to different URLs. When the $to parameter is set to null, the function returns an instance of the Illuminate\Routing\Redirector class. You can use the redirect function to access various methods of the Redirector, such as back(), home(), and to('/'), to control user flow in your application. If you provide a URL as the $to parameter, the redirect function internally calls the to method on the Redirector instance. You can also generate secure (HTTPS) URLs by setting the $secure parameter to true. Additionally, you can change the HTTP status code and supply additional headers by providing arguments for the $status and $headers parameters, respectively.

Laravel

Laravel Application Helper Function: request

John Koster
John Koster
November 20, 2016

The request helper function in Laravel is used to retrieve data from the user's input. To retrieve an instance of Illuminate\Http\Request, call the request method without any arguments. To retrieve an input value, provide at least the $key argument. You can also use the request function as a shortcut to the Request::input method. It can be used to retrieve a subset of the user's input data or to retrieve input with a default value if no input is found.

Laravel

Laravel Application Helper Function: validator

John Koster
John Koster
November 20, 2016

Learn how to use the validator helper function in Laravel to validate input data. The validator function is a versatile helper function that can be used with or without arguments. When used without arguments, it returns an instance of Illuminate\Contracts\Validation\Factory that provides access to validation methods. You can also use the validator function with arguments to directly call the make method on the factory instance.

Laravel

Laravel Application Helper Function: view

John Koster
John Koster
November 20, 2016

The view function in Laravel can be used to return a view instance or a view factory. When called without arguments, it returns the view factory. When called with arguments, it creates a view instance based on the provided view file name, initial data, and additional data to be merged. The provided data can be an array or an object that implements the Arrayable interface. To render a view to a string, you can use the render method on the view instance.

Laravel

Laravel Application Helper: old

John Koster
John Koster
November 20, 2016

The old helper function is used to retrieve an old input item from a previous request. It accepts a $key argument that should be the name of the input item to retrieve. A $default value can also be supplied to be returned if the given $key does not exist. There are alternative methods to achieve the same result, such as using the Input facade or the request() helper function.

Laravel

Laravel Application Helper: policy

John Koster
John Koster
November 20, 2016

Learn how to retrieve a policy instance using the policy helper function in Laravel. This function allows you to retrieve a policy class instance for a given class name or object. If no policies have been registered for the class, an exception will be thrown.

Laravel

Laravel Application Helper: public_path

John Koster
John Koster
November 20, 2016

The public_path function in Laravel returns the path to the public directory. It can also be used to construct paths relative to the public directory by providing a $path argument. The function does not automatically add a trailing slash to the final path, but this can be achieved by using the str_finish function in conjunction with public_path.

Laravel

Laravel Application Helper: response

John Koster
John Koster
November 20, 2016

The response helper function in Laravel can be used in two ways. When no arguments are provided, it returns an instance of Illuminate\Contracts\Routing\ResponseFactory which allows you to use methods like view or json to generate responses. On the other hand, if you pass arguments to the function, it uses the ResponseFactory::make method to create a new instance of Illuminate\Http\Response. You can also set the status code and add additional headers to the response.

Laravel

Laravel Application Helper: storage_path

John Koster
John Koster
November 20, 2016

The storage_path function in Laravel returns the path to the storage directory. If a specific $path is provided, it constructs a path relative to the storage directory. The function does not automatically add a trailing slash to the returned string. To achieve this, you can use the str_finish function with storage_path as its argument. Examples are provided to illustrate its usage.

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