bhavin-gajjar/laravel-coder-lora-train huggingface dataset:
[Laravel 13] Explain octane: FrankenPHP

FrankenPHP is a PHP application server, written in Go, that supports modern web features like early hints, Brotli, and Zstandard compression. When you install Octane and choose FrankenPHP as your server, Octane will automatically download and install the FrankenPHP binary for you.

<a name="frankenphp-via-laravel-sail"></a>
[Laravel 13] Explain octane: FrankenPHP via Laravel Sail

If you plan to develop your application using Laravel Sail, you should run the following commands to install Octane and FrankenPHP:

Next, you should use the octane:install Artisan command to install the FrankenPHP binary:

Finally, add a SUPERVISOR_PHP_COMMAND environment variable to the laravel.test service definition in your application's docker-compose.yml file. This environment variable will contain the command that Sail will use to serve your application using Octane instead of the PHP development server:

To enable HTTPS, HTTP/2, and HTTP/3, apply these modifications instead:

Typically, you should access your FrankenPHP Sail application via https://localhost, as using https://127.0.0.1 requires additional configuration and is discouraged.

<a name="frankenphp-via-docker"></a>
[Laravel 13] Explain octane: FrankenPHP via Docker

Using FrankenPHP's official Docker images can offer improved performance and the use of additional extensions not included with static installations of FrankenPHP. In addition, the official Docker images provide support for running FrankenPHP on platforms it doesn't natively support, such as Windows. FrankenPHP's official Docker images are suitable for both local development and production usage.

You may use the following Dockerfile as a starting point for containerizing your FrankenPHP powered Laravel application:

Then, during development, you may utilize the following Docker Compose file to run your application:

```yaml
[Laravel 13] Explain packages: Package Development

- Introduction
    - A Note on Facades
- Package Discovery
- Service Providers
- Resources
    - Configuration
    - Routes
    - Migrations
    - Language Files
    - Views
    - View Components
    - "About" Artisan Command
- Commands
    - Optimize Commands
    - Reload Commands
- Public Assets
- Publishing File Groups

<a name="introduction"></a>
[Laravel 13] Explain packages: Introduction

Packages are the primary way of adding functionality to Laravel. Packages might be anything from a great way to work with dates like Carbon or a package that allows you to associate files with Eloquent models like Spatie's Laravel Media Library.

There are different types of packages. Some packages are stand-alone, meaning they work with any PHP framework. Carbon and Pest are examples of stand-alone packages. Any of these packages may be used with Laravel by requiring them in your composer.json file.

On the other hand, other packages are specifically intended for use with Laravel. These packages may have routes, controllers, views, and configuration specifically intended to enhance a Laravel application. This guide primarily covers the development of those packages that are Laravel specific.

<a name="a-note-on-facades"></a>
[Laravel 13] Explain packages: A Note on Facades

When writing a Laravel application, it generally does not matter if you use contracts or facades since both provide essentially equal levels of testability. However, when writing packages, your package will not typically have access to all of Laravel's testing helpers. If you would like to be able to write your package tests as if the package were installed inside a typical Laravel application, you may use the Orchestral Testbench package.

<a name="package-discovery"></a>
[Laravel 13] Explain packages: Package Discovery

A Laravel application's bootstrap/providers.php file contains the list of service providers that should be loaded by Laravel. However, instead of requiring users to manually add your service provider to the list, you may define the provider in the extra section of your package's composer.json file so that it is automatically loaded by Laravel. In addition to service providers, you may also list any facades you would like to be registered:

Once your package has been configured for discovery, Laravel will automatically register its service providers and facades when it is installed, creating a convenient installation experience for your package's users.

<a name="opting-out-of-package-discovery"></a>
[Laravel 13] Explain packages: Service Providers

Service providers are the connection point between your package and Laravel. A service provider is responsible for binding things into Laravel's service container and informing Laravel where to load package resources such as views, configuration, and language files.

A service provider extends the Illuminate\Support\ServiceProvider class and contains two methods: register and boot. The base ServiceProvider class is located in the illuminate/support Composer package, which you should add to your own package's dependencies. To learn more about the structure and purpose of service providers, check out their documentation.

<a name="resources"></a>
[Laravel 13] Explain pagination: Database: Pagination

- Introduction
- Basic Usage
    - Paginating Query Builder Results
    - Paginating Eloquent Results
    - Cursor Pagination
    - Manually Creating a Paginator
    - Customizing Pagination URLs
- Displaying Pagination Results
    - Adjusting the Pagination Link Window
    - Converting Results to JSON
- Customizing the Pagination View
    - Using Bootstrap
- Paginator and LengthAwarePaginator Instance Methods
- Cursor Paginator Instance Methods

<a name="introduction"></a>
[Laravel 13] Explain pagination: Introduction

In other frameworks, pagination can be very painful. We hope Laravel's approach to pagination will be a breath of fresh air. Laravel's paginator is integrated with the query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database records with zero configuration.

By default, the HTML generated by the paginator is compatible with the Tailwind CSS framework; however, Bootstrap pagination support is also available.

<a name="tailwind"></a>
[Laravel 13] Explain pagination: Paginating Query Builder Results

There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent query. The paginate method automatically takes care of setting the query's "limit" and "offset" based on the current page being viewed by the user. By default, the current page is detected by the value of the page query string argument on the HTTP request. This value is automatically detected by Laravel, and is also automatically inserted into links generated by the paginator.

In this example, the only argument passed to the paginate method is the number of items you would like displayed "per page". In this case, let's specify that we would like to display 15 items per page:

<a name="simple-pagination"></a>
[Laravel 13] Explain pagination: Simple Pagination

The paginate method counts the total number of records matched by the query before retrieving the records from the database. This is done so that the paginator knows how many pages of records there are in total. However, if you do not plan to show the total number of pages in your application's UI then the record count query is unnecessary.

Therefore, if you only need to display simple "Next" and "Previous" links in your application's UI, you may use the simplePaginate method to perform a single, efficient query:

<a name="paginating-eloquent-results"></a>
[Laravel 13] Explain pagination: Paginating Eloquent Results

You may also paginate Eloquent queries. In this example, we will paginate the App\Models\User model and indicate that we plan to display 15 records per page. As you can see, the syntax is nearly identical to paginating query builder results:

Of course, you may call the paginate method after setting other constraints on the query, such as where clauses:

You may also use the simplePaginate method when paginating Eloquent models:

Similarly, you may use the cursorPaginate method to cursor paginate Eloquent models:

<a name="multiple-paginator-instances-per-page"></a>
[Laravel 13] Explain passport: Laravel Passport

- Introduction
    - Passport or Sanctum?
- Installation
    - Deploying Passport
    - Upgrading Passport
- Configuration
    - Token Lifetimes
    - Overriding Default Models
    - Overriding Routes
- Authorization Code Grant
    - Managing Clients
    - Requesting Tokens
    - Managing Tokens
    - Refreshing Tokens
    - Revoking Tokens
    - Purging Tokens
- Authorization Code Grant With PKCE
    - Creating the Client
    - Requesting Tokens
- Device Authorization Grant
    - Creating a Device Code Grant Client
    - Requesting Tokens
- Password Grant
    - Creating a Password Grant Client
    - Requesting Tokens
    - Requesting All Scopes
    - Customizing the User Provider
    - Customizing the Username Field
    - Customizing the Password Validation
- Implicit Grant
- Client Credentials Grant
- Personal Access Tokens
    - Creating a Personal Access Client
    - Customizing the User Provider
    - Managing Personal Access Tokens
- Protecting Routes
    - Via Middleware
    - Passing the Access Token
- Token Scopes
    - Defining Scopes
    - Default Scope
    - Assigning Scopes to Tokens
    - Checking Scopes
- SPA Authentication
- Events
- Testing

<a name="introduction"></a>
[Laravel 13] Explain passport: Introduction

Laravel Passport provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. Passport is built on top of the League OAuth2 server that is maintained by Andy Millington and Simon Hamp.

> [!NOTE]
> This documentation assumes you are already familiar with OAuth2. If you do not know anything about OAuth2, consider familiarizing yourself with the general terminology and features of OAuth2 before continuing.

<a name="passport-or-sanctum"></a>
[Laravel 13] Explain passport: Passport or Sanctum?

Before getting started, you may wish to determine if your application would be better served by Laravel Passport or Laravel Sanctum. If your application absolutely needs to support OAuth2, then you should use Laravel Passport.

However, if you are attempting to authenticate a single-page application, mobile application, or issue API tokens, you should use Laravel Sanctum. Laravel Sanctum does not support OAuth2; however, it provides a much simpler API authentication development experience.

<a name="installation"></a>
[Laravel 13] Explain passport: Installation

You may install Laravel Passport via the install:api Artisan command:

This command will publish and run the database migrations necessary for creating the tables your application needs to store OAuth2 clients and access tokens. The command will also create the encryption keys required to generate secure access tokens.

After running the install:api command, add the Laravel\Passport\HasApiTokens trait and Laravel\Passport\Contracts\OAuthenticatable interface to your App\Models\User model. This trait will provide a few helper methods to your model which allow you to inspect the authenticated user's token and scopes:

Finally, in your application's config/auth.php configuration file, you should define an api authentication guard and set the driver option to passport. This will instruct your application to use Passport's TokenGuard when authenticating incoming API requests:

<a name="deploying-passport"></a>
[Laravel 13] Explain passport: Deploying Passport

When deploying Passport to your application's servers for the first time, you will likely need to run the passport:keys command. This command generates the encryption keys Passport needs in order to generate access tokens. The generated keys are not typically kept in source control:

If necessary, you may define the path where Passport's keys should be loaded from. You may use the Passport::loadKeysFrom method to accomplish this. Typically, this method should be called from the boot method of your application's App\Providers\AppServiceProvider class:

<a name="loading-keys-from-the-environment"></a>
[Laravel 13] Explain passwords: Introduction

Most web applications provide a way for users to reset their forgotten passwords. Rather than forcing you to re-implement this by hand for every application you create, Laravel provides convenient services for sending password reset links and secure resetting passwords.

> [!NOTE]
> Want to get started fast? Install a Laravel application starter kit in a fresh Laravel application. Laravel's starter kits will take care of scaffolding your entire authentication system, including resetting forgotten passwords.

<a name="configuration"></a>
[Laravel 13] Explain passwords: Configuration

Your application's password reset configuration file is stored at config/auth.php. Be sure to review the options available to you in this file. By default, Laravel is configured to use the database password reset driver.

The password reset driver configuration option defines where password reset data will be stored. Laravel includes two drivers:

<div class="content-list" markdown="1">

- database - password reset data is stored in a relational database.
- cache - password reset data is stored in one of your cache-based stores.

</div>

<a name="driver-prerequisites"></a>
[Laravel 13] Explain passwords: Cache

There is also a cache driver available for handling password resets, which does not require a dedicated database table. Entries are keyed by the user's email address, so ensure you are not using email addresses as a cache key elsewhere in your application:

To prevent a call to artisan cache:clear from flushing your password reset data, you can optionally specify a separate cache store with the store configuration key. The value should correspond to a store configured in your config/cache.php configuration value.

<a name="model-preparation"></a>
[Laravel 13] Explain passwords: Model Preparation

Before using the password reset features of Laravel, your application's App\Models\User model must use the Illuminate\Notifications\Notifiable trait. Typically, this trait is already included on the default App\Models\User model that is created with new Laravel applications.

Next, verify that your App\Models\User model implements the Illuminate\Contracts\Auth\CanResetPassword contract. The App\Models\User model included with the framework already implements this interface, and uses the Illuminate\Auth\Passwords\CanResetPassword trait to include the methods needed to implement the interface.

<a name="configuring-trusted-hosts"></a>
[Laravel 13] Explain pennant: Laravel Pennant

- Introduction
- Installation
- Configuration
- Defining Features
    - Class Based Features
- Checking Features
    - Conditional Execution
    - The HasFeatures Trait
    - Blade Directive
    - Middleware
    - Intercepting Feature Checks
    - In-Memory Cache
- Scope
    - Specifying the Scope
    - Default Scope
    - Nullable Scope
    - Identifying Scope
    - Serializing Scope
- Rich Feature Values
- Retrieving Multiple Features
- Eager Loading
- Updating Values
    - Bulk Updates
    - Purging Features
- Testing
- Adding Custom Pennant Drivers
    - Implementing the Driver
    - Registering the Driver
    - Defining Features Externally
- Events

<a name="introduction"></a>
[Laravel 13] Explain pennant: Configuration

After publishing Pennant's assets, its configuration file will be located at config/pennant.php. This configuration file allows you to specify the default storage mechanism that will be used by Pennant to store resolved feature flag values.

Pennant includes support for storing resolved feature flag values in an in-memory array via the array driver. Or, Pennant can store resolved feature flag values persistently in a relational database via the database driver, which is the default storage mechanism used by Pennant.

<a name="defining-features"></a>
[Laravel 13] Explain pennant: Defining Features

To define a feature, you may use the define method offered by the Feature facade. You will need to provide a name for the feature, as well as a closure that will be invoked to resolve the feature's initial value.

Typically, features are defined in a service provider using the Feature facade. The closure will receive the "scope" for the feature check. Most commonly, the scope is the currently authenticated user. In this example, we will define a feature for incrementally rolling out a new API to our application's users:

As you can see, we have the following rules for our feature:

- All internal team members should be using the new API.
- Any high traffic customers should not be using the new API.
- Otherwise, the feature should be randomly assigned to users with a 1 in 100 chance of being active.

The first time the new-api feature is checked for a given user, the result of the closure will be stored by the storage driver. The next time the feature is checked against the same user, the value will be retrieved from storage and the closure will not be invoked.

For convenience, if a feature definition only returns a lottery, you may omit the closure completely:

    Feature::define('site-redesign', Lottery::odds(1, 1000));

<a name="class-based-features"></a>
[Laravel 13] Explain pennant: Class Based Features

Pennant also allows you to define class-based features. Unlike closure-based feature definitions, there is no need to register a class-based feature in a service provider. To create a class-based feature, you may invoke the pennant:feature Artisan command. By default, the feature class will be placed in your application's app/Features directory:

When writing a feature class, you only need to define a resolve method, which will be invoked to resolve the feature's initial value for a given scope. Again, the scope will typically be the currently authenticated user:

If you would like to manually resolve an instance of a class-based feature, you may invoke the instance method on the Feature facade:

> [!NOTE]
> Feature classes are resolved via the container, so you may inject dependencies into the feature class's constructor when needed.
[Laravel 13] Explain pint: Introduction

Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP CS Fixer and makes it simple to ensure that your code style stays clean and consistent.

Pint is automatically installed with all new Laravel applications so you may start using it immediately. By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.

<a name="installation"></a>
[Laravel 13] Explain pint: Running Pint

You can instruct Pint to fix code style issues by invoking the pint binary that is available in your project's vendor/bin directory:

If you would like Pint to run in parallel mode (experimental) for improved performance, you may use the --parallel option:

Parallel mode also allows you to specify the maximum number of processes to run via the --max-processes option. If this option is not provided, Pint will use every available core on your machine:

You may also run Pint on specific files or directories:

Pint will display a thorough list of all of the files that it updates. You can view even more detail about Pint's changes by providing the -v option when invoking Pint:

If you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the --test option. Pint will return a non-zero exit code if any code style errors are found:

If you would like Pint to only modify the files that differ from the provided branch according to Git, you may use the --diff=[branch] option. This can be effectively used in your CI environment (like GitHub actions) to save time by only inspecting new or modified files:

If you would like Pint to only modify the files that have uncommitted changes according to Git, you may use the --dirty option:

If you would like Pint to fix any files with code style errors but also exit with a non-zero exit code if any errors were fixed, you may use the --repair option:

<a name="configuring-pint"></a>
[Laravel 13] Explain pint: Configuring Pint

As previously mentioned, Pint does not require any configuration. However, if you wish to customize the presets, rules, or inspected folders, you may do so by creating a pint.json file in your project's root directory:

In addition, if you wish to use a pint.json from a specific directory, you may provide the --config option when invoking Pint:

<a name="presets"></a>
[Laravel 13] Explain pint: Presets

Presets define a set of rules that can be used to fix code style issues in your code. By default, Pint uses the laravel preset, which fixes issues by following the opinionated coding style of Laravel. However, you may specify a different preset by providing the --preset option to Pint:

If you wish, you may also set the preset in your project's pint.json file:

Pint's currently supported presets are: laravel, per, psr12, symfony, and empty.

<a name="rules"></a>
[Laravel 13] Explain precognition: Introduction

Laravel Precognition allows you to anticipate the outcome of a future HTTP request. One of the primary use cases of Precognition is the ability to provide "live" validation for your frontend JavaScript application without having to duplicate your application's backend validation rules.

When Laravel receives a "precognitive request", it will execute all of the route's middleware and resolve the route's controller dependencies, including validating form requests - but it will not actually execute the route's controller method.

> [!NOTE]
> As of Inertia 2.3, Precognition support is built-in. Please consult the Inertia Forms documentation for more information. Earlier Inertia versions require Precognition 0.x.

<a name="live-validation"></a>
[Laravel 13] Explain precognition: Using Vue

Using Laravel Precognition, you can offer live validation experiences to your users without having to duplicate your validation rules in your frontend Vue application. To illustrate how it works, let's build a form for creating new users within our application.

First, to enable Precognition for a route, the HandlePrecognitiveRequests middleware should be added to the route definition. You should also create a form request to house the route's validation rules:

Next, you should install the Laravel Precognition frontend helpers for Vue via NPM:

With the Laravel Precognition package installed, you can now create a form object using Precognition's useForm function, providing the HTTP method (post), the target URL (/users), and the initial form data.

Then, to enable live validation, invoke the form's validate method on each input's change event, providing the input's name:

Now, as the form is filled by the user, Precognition will provide live validation output powered by the validation rules in the route's form request. When the form's inputs are changed, a debounced "precognitive" validation request will be sent to your Laravel application. You may configure the debounce timeout by calling the form's setValidationTimeout function:

When a validation request is in-flight, the form's validating property will be true:

Any validation errors returned during a validation request or a form submission will automatically populate the form's errors object:

You can determine if the form has any errors using the form's hasErrors property:

You may also determine if an input has passed or failed validation by passing the input's name to the form's valid and invalid functions, respectively:

> [!WARNING]
> A form input will only appear as valid or invalid once it has changed and a validation response has been received.

If you are validating a subset of a form's inputs with Precognition, it can be useful to manually clear errors. You may use the form's forgetError function to