The Blog

Laravel 5

Laravel 5: Performing HTTP Redirects With redirect

John Koster
John Koster
April 14, 2018

The redirect helper function in Laravel is a useful helper function that simplifies the task of returning HTTP redirects from controller actions or routes. It has a signature that includes parameters for the target URL, HTTP status code, headers, and secure option. By default, when the target URL is null, the function returns an instance of "Illuminate\\Routing\\Redirector". The Redirector class has many methods to control user flow, such as back(), home(), and to(). To redirect to a specific path, you can pass the path as an argument to the redirect function or use the to() method of the Redirector instance. If you want to redirect to a secure URL, you can pass true as an argument for the $secure parameter. Additionally, you can supply extra headers by providing an argument for $status and $headers.

Laravel 5

Laravel 5: Recover From Possible Exceptions With rescue

John Koster
John Koster
April 14, 2018

The rescue function in PHP allows you to attempt the execution of an operation that may throw an exception. By providing a default value through the $rescue parameter, you can specify what value should be returned if the operation fails. Additionally, the rescue function can log the inner exception using the report helper function. This can be helpful for debugging and error handling purposes. An alternative to using rescue is the traditional try/catch control structure, which achieves the same goal but with slightly different syntax.

Laravel 5

Laravel 5: Redirecting Users to the Previous Page With back

John Koster
John Koster
April 14, 2018

The back helper function is used to create a redirect response to the user's previous location. It can be used to control the status code and headers of the response. The function returns an instance of "Illuminate\Http\RedirectResponse". The back method can be accessed using the Redirect facade or the redirect helper function. The status code and headers can be changed by providing arguments for the $status and $headers parameters respectively. An example of supplying extra headers is also shown.

Laravel 5

Laravel 5: Rendering Views to Strings and Returning View Responses With view

John Koster
John Koster
April 14, 2018

Learn how to use the view function in Laravel to return a view instance or check if a view exists. The function allows you to pass a view file name, data, and merge data. You can also render a view to a string for further processing.

Laravel 5

Laravel 5: Reporting Application Exceptions With report

John Koster
John Koster
April 14, 2018

The report function is used to report an exception to the application's exception handler. It invokes the report method of the application exception handler with the provided exception. To use it, simply call the report function and pass in the exception you want to report.

Laravel 5

Laravel 5: Resolving Authentication Policies With policy

John Koster
John Koster
April 14, 2018

The policy helper function retrieves a policy instance for a given class. It can be called with either a string or an object instance. If no policies have been registered for the class, an exception will be thrown. To use custom policies, they need to be mapped to their associated model class, typically within the AuthServiceProvider file. The policy helper function internally calls the getPolicyFor method on the authentication gate instance.

Laravel 5

Laravel 5: Resolving Concrete Implementations From the Service Container With resolve

John Koster
John Koster
April 14, 2018

The resolve helper function is used to resolve a class instance from the Service Container. This function can be used to resolve any dependency from the Service Container as long as its constructor parameter dependencies can be resolved. Unlike the app helper function, it does not allow parameters to be supplied to the Service Container when resolving the dependency. For example, the resolve function can be used to resolve Laravel's event dispatcher from the Service Container by calling resolve('events').

Laravel 5

Laravel 5: Retrieving Environment Variables With env

John Koster
John Koster
April 14, 2018

The env function in PHP is used to retrieve the value of an environment variable. It allows you to specify a default value to be returned if the variable is not set. The function automatically converts boolean string representations and null representations into their corresponding PHP values.

Laravel 5

Laravel 5: Throwing HTTP Exceptions With abort

John Koster
John Koster
April 14, 2018

Learn how to use the abort function in Symfony to throw and handle HTTP exceptions. When called, the abort function will throw an instance of Symfony\Component\HttpKernel\Exception\HttpException with the provided code, message, and headers. If the code is 404, it will throw Symfony\Component\HttpKernel\Exception\NotFoundHttpException using only the user-supplied message. Check out the example to see how to use the abort function to handle unauthorized access with a 401 error code.

Laravel 5

Laravel 5: Triggering Events With event

John Koster
John Koster
April 14, 2018

The event helper function allows you to conveniently dispatch events and their listeners. You can dispatch events by their name or by instantiating a new instance of the event class. The function also supports object-based events without the need for an event dispatcher dependency. The function returns an array of responses from the listeners.

Latest posts

Where Things get Good: Moving on to Forte Development Phase 1

Wrapping up Forte Phase 0 with the lexer and parser now in private alpha, and kicking off Phase 1 wi...

Read more
Forte Update: Backtracking, Metadata, HTML Validation, and More

A Forte development update: the parser now supports backtracking, improvements to node metadata, ide...

Read more
Parsing HTML and Blade Attributes in Forte

Wrapping up attribute parsing in Forte's HTML parser, from simple HTML attributes to complex, edge-c...

Read more
Switch Statements and Parser Extensions in Forte

Exploring how Forte's parser extensions can be used to handle complex Blade directives like nested s...

Read more
Parsing Blade Comments in Forte

Digging into parsing Blade and HTML comments while building Forte's HTML parser for Laravel Blade.

Read more
Thoughts on HTML Elements and Blade Components in Forte

This week I’m tackling Forte's HTML parser - consolidating Blade, Flux, and Livewire components into...

Read more