The Blog

Laravel 5

Laravel 5: Conditionally Throwing HTTP Exceptions With abort_if

John Koster
John Koster
April 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

Laravel 5: Conditionally Throwing HTTP Exceptions With abort_unless

John Koster
John Koster
April 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

Laravel 5: Creating Eloquent Models for Testing With factory

John Koster
John Koster
April 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

Laravel 5: Decrypting Strings With decrypt

John Koster
John Koster
April 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

Laravel 5: Dispatching Queued Jobs Immediately With dispatch_now

John Koster
John Koster
April 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.

Laravel 5

Laravel 5: Dispatching Queued Jobs With dispatch

John Koster
John Koster
April 14, 2018

Learn how to use the dispatch helper function in Laravel to push a new job onto the job queue. This function returns a new instance of "\\Illuminate\\Foundation\\Bus\\PendingDispatch", which allows you to modify properties about the pending job operation, such as its priority level. Find examples of how to use the dispatch function, including alternative methods for invoking it. Plus, discover how to make adjustments to a job's properties before it is added to the job queue.

Laravel 5

Laravel 5: Encrypting Strings With encrypt

John Koster
John Koster
April 14, 2018

The encrypt helper function encrypts a given string value by calling the encrypt method on the Encrypter instance resolved from the Service Container. You can use the encrypt function directly or through the Crypt facade. Alternatively, you can retrieve an instance from the Service Container and call the encrypt method on it.

Laravel 5

Laravel 5: Generating an HTML Field for HTTP Verbs With method_field

John Koster
John Koster
April 14, 2018

The method_field helper function in Laravel is used to generate a hidden HTML input field with the name _method and a specified value. This function returns a new instance of Illuminate\Support\HtmlString. You can use this function to generate HTML input fields for various HTTP methods such as PUT, POST, GET, PATCH, and DELETE. For example, calling method_field('PUT') will generate <input type="hidden" name="_method" value="PUT">. Similarly, calling method_field('POST') will generate <input type="hidden" name="_method" value="POST">.

Laravel 5

Laravel 5: Generating CSRF Hidden HTML Fields With csrf_field

John Koster
John Koster
April 14, 2018

The csrf_field function generates a hidden HTML element containing the CSRF token value, which can help prevent cross-site request forgeries. It simplifies the process of including the token in your forms, reducing the need for manual HTML input elements. The function can be used in plain PHP or with Blade syntax in Laravel.

Laravel 5

Laravel 5: Generating CSRF Session Tokens With csrf_token

John Koster
John Koster
April 14, 2018

Learn about the csrf_token function in Laravel, which retrieves the CSRF token from the session storage. The CSRF token is a random string 40 characters long, generated using the str_random(40) function call. You can use the csrf_token function to generate the token and include it in your HTML forms using the csrf_field method, making your forms secure against cross-site request forgery attacks.

Latest posts

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
Laracon, Blade and What's Next

Recapping Laracon in Denver with the Statamic team, this post introduces Forte - a new Blade extensi...

Read more