bhavin-gajjar/laravel-coder-lora-train huggingface dataset:
[Laravel 11] 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 11] 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 11] 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-jit"></a>
[Laravel 11] 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:

    <?php

    namespace App\Http\Controllers;

    use App\Http\Controllers\Controller;
    use Illuminate\Support\Facades\DB;
    use Illuminate\View\View;

    class UserController extends Controller
    {
        /**
         * Show all application users.
         */
        public function index(): View
        {
            return view('user.index', [
                'users' => DB::table('users')->paginate(15)
            ]);
        }
    }

<a name="simple-pagination"></a>
[Laravel 11] 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:

    $users = DB::table('users')->simplePaginate(15);

<a name="paginating-eloquent-results"></a>
[Laravel 11] Explain passport: Laravel Passport

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

<a name="introduction"></a>
[Laravel 11] 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.

> [!WARNING]  
> 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 11] 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 11] 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.

Additionally, this command will ask if you would like to use UUIDs as the primary key value of the Passport Client model instead of auto-incrementing integers.

After running the install:api command, add the Laravel\Passport\HasApiTokens trait 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:

    <?php

    namespace App\Models;

    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Notifications\Notifiable;
    use Laravel\Passport\HasApiTokens;

    class User extends Authenticatable
    {
        use HasApiTokens, HasFactory, Notifiable;
    }

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:

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

<a name="deploying-passport"></a>
[Laravel 11] 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:

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Passport::loadKeysFrom(__DIR__.'/../secrets/oauth');
    }

<a name="loading-keys-from-the-environment"></a>
[Laravel 11] 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="model-preparation"></a>
[Laravel 11] 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="database-preparation"></a>
[Laravel 11] Explain passwords: Configuring Trusted Hosts

By default, Laravel will respond to all requests it receives regardless of the content of the HTTP request's Host header. In addition, the Host header's value will be used when generating absolute URLs to your application during a web request.

Typically, you should configure your web server, such as Nginx or Apache, to only send requests to your application that match a given hostname. However, if you do not have the ability to customize your web server directly and need to instruct Laravel to only respond to certain hostnames, you may do so by using the trustHosts middleware method in your application's bootstrap/app.php file. This is particularly important when your application offers password reset functionality.

To learn more about this middleware method, please consult the TrustHosts middleware documentation.

<a name="routing"></a>
[Laravel 11] 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 11] 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 11] 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 11] 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 11] 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:

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 11] 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 11] Explain precognition: Precognition

- Introduction
- Live Validation
    - Using Vue
    - Using Vue and Inertia
    - Using React
    - Using React and Inertia
    - Using Alpine and Blade
    - Configuring Axios
- Customizing Validation Rules
- Handling File Uploads
- Managing Side-Effects
- Testing

<a name="introduction"></a>
[Laravel 11] 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. Precognition pairs especially well with Laravel's Inertia-based starter kits.

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.

<a name="live-validation"></a>
[Laravel 11] 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 t
[Laravel 11] Explain precognition: Using Vue and Inertia

> [!NOTE]  
> If you would like a head start when developing your Laravel application with Vue and Inertia, consider using one of our starter kits. Laravel's starter kits provide backend and frontend authentication scaffolding for your new Laravel application.

Before using Precognition with Vue and Inertia, be sure to review our general documentation on using Precognition with Vue. When using Vue with Inertia, you will need to install the Inertia compatible Precognition library via NPM:

Once installed, Precognition's useForm function will return an Inertia form helper augmented with the validation features discussed above.

The form helper's submit method has been streamlined, removing the need to specify the HTTP method or URL. Instead, you may pass Inertia's visit options as the first and only argument. In addition, the submit method does not return a Promise as seen in the Vue example above. Instead, you may provide any of Inertia's supported event callbacks in the visit options given to the submit method:

<a name="using-react"></a>
[Laravel 11] Explain precognition: Using React

Using Laravel Precognition, you can offer live validation experiences to your users without having to duplicate your validation rules in your frontend React 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 React 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.

To enable live validation, you should listen to each input's change and blur event. In the change event handler, you should set the form's data with the setData function, passing the input's name and new value. Then, in the blur event handler invoke the form's validate method, 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 r
[Laravel 11] Explain processes: Processes

- Introduction
- Invoking Processes
    - Process Options
    - Process Output
    - Pipelines
- Asynchronous Processes
    - Process IDs and Signals
    - Asynchronous Process Output
- Concurrent Processes
    - Naming Pool Processes
    - Pool Process IDs and Signals
- Testing
    - Faking Processes
    - Faking Specific Processes
    - Faking Process Sequences
    - Faking Asynchronous Process Lifecycles
    - Available Assertions
    - Preventing Stray Processes

<a name="introduction"></a>
[Laravel 11] Explain processes: Invoking Processes

To invoke a process, you may use the run and start methods offered by the Process facade. The run method will invoke a process and wait for the process to finish executing, while the start method is used for asynchronous process execution. We'll examine both approaches within this documentation. First, let's examine how to invoke a basic, synchronous process and inspect its result:

Of course, the Illuminate\Contracts\Process\ProcessResult instance returned by the run method offers a variety of helpful methods that may be used to inspect the process result:

<a name="throwing-exceptions"></a>
[Laravel 11] Explain prompts: Prompts

- Introduction
- Installation
- Available Prompts
    - Text
    - Textarea
    - Password
    - Confirm
    - Select
    - Multi-select
    - Suggest
    - Search
    - Multi-search
    - Pause
- Transforming Input Before Validation
- Forms
- Informational Messages
- Tables
- Spin
- Progress Bar
- Clearing the Terminal
- Terminal Considerations
- Unsupported Environments and Fallbacks

<a name="introduction"></a>
[Laravel 11] Explain prompts: Introduction

Laravel Prompts is a PHP package for adding beautiful and user-friendly forms to your command-line applications, with browser-like features including placeholder text and validation.

<img src="https://laravel.com/img/docs/prompts-example.png">

Laravel Prompts is perfect for accepting user input in your Artisan console commands, but it may also be used in any command-line PHP project.

> [!NOTE]  
> Laravel Prompts supports macOS, Linux, and Windows with WSL. For more information, please see our documentation on unsupported environments & fallbacks.

<a name="installation"></a>