The Blog

Laravel

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.

Laravel

Laravel Application Helper: config_path

John Koster
John Koster
November 20, 2016

The config_path function in Laravel retrieves the path to the config directory and can be used to construct paths relative to it. An optional $path parameter allows for specific file paths to be constructed. In this example, the resulting paths are displayed as comments above the function calls.

Laravel

Laravel Application Helper: database_path

John Koster
John Koster
November 20, 2016

The database_path function in Laravel retrieves the path to the database directory. By supplying a $path, you can construct paths relative to the database directory. For example, calling database_path() will return the path to the /home/vagrant/Code/Laravel/database directory, while database_path('migrations') will return the path to the /home/vagrant/Code/Laravel/migrations directory. Additionally, the str_finish function can be used to ensure a trailing slash is added to the path, as shown in the example str_finish(database_path('seeds'), '/').

Laravel

Laravel Application Helper Function: abort

John Koster
John Koster
November 20, 2016

The abort function is used to throw an HTTP exception with the given code, message, and headers. This exception can be caught and handled in the application's kernel. If the code is 404, the function will return a "Not Found" exception using the provided message. In the example, if the $user object does not have the admin property set to true, the code will abort with a 401 unauthorized access error.

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