bhavin-gajjar/laravel-coder-lora-train huggingface dataset:
[Laravel 12] Explain queries: Database: Query Builder

- Introduction
- Running Database Queries
    - Chunking Results
    - Streaming Results Lazily
    - Aggregates
- Select Statements
- Raw Expressions
- Joins
- Unions
- Basic Where Clauses
    - Where Clauses
    - Or Where Clauses
    - Where Not Clauses
    - Where Any / All / None Clauses
    - JSON Where Clauses
    - Additional Where Clauses
    - Logical Grouping
- Advanced Where Clauses
    - Where Exists Clauses
    - Subquery Where Clauses
    - Full Text Where Clauses
    - Vector Similarity Clauses
- Ordering, Grouping, Limit and Offset
    - Ordering
    - Grouping
    - Limit and Offset
- Conditional Clauses
- Insert Statements
    - Upserts
- Update Statements
    - Updating JSON Columns
    - Increment and Decrement
- Delete Statements
- Pessimistic Locking
- Reusable Query Components
- Debugging

<a name="introduction"></a>
[Laravel 12] Explain queries: Introduction

Laravel's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works perfectly with all of Laravel's supported database systems.

The Laravel query builder uses PDO parameter binding to protect your application against SQL injection attacks. There is no need to clean or sanitize strings passed to the query builder as query bindings.

> [!WARNING]
> PDO does not support binding column names. Therefore, you should never allow user input to dictate the column names referenced by your queries, including "order by" columns.

<a name="running-database-queries"></a>
[Laravel 12] Explain queries: Retrieving All Rows From a Table

You may use the table method provided by the DB facade to begin a query. The table method returns a fluent query builder instance for the given table, allowing you to chain more constraints onto the query and then finally retrieve the results of the query using the get method:

The get method returns an Illuminate\Support\Collection instance containing the results of the query where each result is an instance of the PHP stdClass object. You may access each column's value by accessing the column as a property of the object:

> [!NOTE]
> Laravel collections provide a variety of extremely powerful methods for mapping and reducing data. For more information on Laravel collections, check out the collection documentation.

<a name="retrieving-a-single-row-column-from-a-table"></a>
[Laravel 12] Explain queries: Retrieving a Single Row / Column From a Table

If you just need to retrieve a single row from a database table, you may use the DB facade's first method. This method will return a single stdClass object:

If you would like to retrieve a single row from a database table, but throw an Illuminate\Database\RecordNotFoundException if no matching row is found, you may use the firstOrFail method. If the RecordNotFoundException is not caught, a 404 HTTP response is automatically sent back to the client:

If you don't need an entire row, you may extract a single value from a record using the value method. This method will return the value of the column directly:

To retrieve a single row by its id column value, use the find method:

<a name="retrieving-a-list-of-column-values"></a>
[Laravel 12] Explain queues: Queues

- Introduction
    - Connections vs. Queues
    - Driver Notes and Prerequisites
- Creating Jobs
    - Generating Job Classes
    - Class Structure
    - Unique Jobs
    - Encrypted Jobs
- Job Middleware
    - Rate Limiting
    - Preventing Job Overlaps
    - Throttling Exceptions
    - Skipping Jobs
- Dispatching Jobs
    - Delayed Dispatching
    - Synchronous Dispatching
    - Jobs & Database Transactions
    - Job Chaining
    - Customizing The Queue and Connection
    - Specifying Max Job Attempts / Timeout Values
    - SQS FIFO and Fair Queues
    - Queue Failover
    - Error Handling
- Job Batching
    - Defining Batchable Jobs
    - Dispatching Batches
    - Chains and Batches
    - Adding Jobs to Batches
    - Inspecting Batches
    - Cancelling Batches
    - Batch Failures
    - Pruning Batches
    - Storing Batches in DynamoDB
- Queueing Closures
- Running the Queue Worker
    - The queue:work Command
    - Queue Priorities
    - Queue Workers and Deployment
    - Job Expirations and Timeouts
    - Pausing and Resuming Queue Workers
- Supervisor Configuration
- Dealing With Failed Jobs
    - Cleaning Up After Failed Jobs
    - Retrying Failed Jobs
    - Ignoring Missing Models
    - Pruning Failed Jobs
    - Storing Failed Jobs in DynamoDB
    - Disabling Failed Job Storage
    - Failed Job Events
- Clearing Jobs From Queues
- Monitoring Your Queues
- Testing
    - Faking a Subset of Jobs
    - Testing Job Chains
    - Testing Job Batches
    - Testing Job / Queue Interactions
- Job Events

<a name="introduction"></a>
[Laravel 12] Explain queues: Introduction

While building your web application, you may have some tasks, such as parsing and storing an uploaded CSV file, that take too long to perform during a typical web request. Thankfully, Laravel allows you to easily create queued jobs that may be processed in the background. By moving time intensive tasks to a queue, your application can respond to web requests with blazing speed and provide a better user experience to your customers.

Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQS, Redis, or even a relational database.

Laravel's queue configuration options are stored in your application's config/queue.php configuration file. In this file, you will find connection configurations for each of the queue drivers that are included with the framework, including the database, Amazon SQS, Redis, and Beanstalkd drivers, as well as a synchronous driver that will execute jobs immediately (for use during development or testing). A null queue driver is also included which discards queued jobs.

> [!NOTE]
> Laravel Horizon is a beautiful dashboard and configuration system for your Redis powered queues. Check out the full Horizon documentation for more information.

<a name="connections-vs-queues"></a>
[Laravel 12] Explain queues: Connections vs. Queues

Before getting started with Laravel queues, it is important to understand the distinction between "connections" and "queues". In your config/queue.php configuration file, there is a connections configuration array. This option defines the connections to backend queue services such as Amazon SQS, Beanstalk, or Redis. However, any given queue connection may have multiple "queues" which may be thought of as different stacks or piles of queued jobs.

Note that each connection configuration example in the queue configuration file contains a queue attribute. This is the default queue that jobs will be dispatched to when they are sent to a given connection. In other words, if you dispatch a job without explicitly defining which queue it should be dispatched to, the job will be placed on the queue that is defined in the queue attribute of the connection configuration:

Some applications may not need to ever push jobs onto multiple queues, instead preferring to have one simple queue. However, pushing jobs to multiple queues can be especially useful for applications that wish to prioritize or segment how jobs are processed, since the Laravel queue worker allows you to specify which queues it should process by priority. For example, if you push jobs to a high queue, you may run a worker that gives them higher processing priority:

<a name="driver-prerequisites"></a>
[Laravel 12] Explain rate limiting: Basic Usage

The Illuminate\Support\Facades\RateLimiter facade may be used to interact with the rate limiter. The simplest method offered by the rate limiter is the attempt method, which rate limits a given callback for a given number of seconds.

The attempt method returns false when the callback has no remaining attempts available; otherwise, the attempt method will return the callback's result or true. The first argument accepted by the attempt method is a rate limiter "key", which may be any string of your choosing that represents the action being rate limited:

If necessary, you may provide a fourth argument to the attempt method, which is the "decay rate", or the number of seconds until the available attempts are reset. For example, we can modify the example above to allow five attempts every two minutes:

<a name="manually-incrementing-attempts"></a>
[Laravel 12] Explain rate limiting: Manually Incrementing Attempts

If you would like to manually interact with the rate limiter, a variety of other methods are available. For example, you may invoke the tooManyAttempts method to determine if a given rate limiter key has exceeded its maximum number of allowed attempts per minute:

Alternatively, you may use the remaining method to retrieve the number of attempts remaining for a given key. If a given key has retries remaining, you may invoke the increment method to increment the number of total attempts:

If you would like to increment the value for a given rate limiter key by more than one, you may provide the desired amount to the increment method:

<a name="determining-limiter-availability"></a>
[Laravel 12] Explain redis: Introduction

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets.

Before using Redis with Laravel, we encourage you to install and use the PhpRedis PHP extension via PECL. The extension is more complex to install compared to "user-land" PHP packages but may yield better performance for applications that make heavy use of Redis. If you are using Laravel Sail, this extension is already installed in your application's Docker container.

If you are unable to install the PhpRedis extension, you may install the predis/predis package via Composer. Predis is a Redis client written entirely in PHP and does not require any additional extensions:

<a name="configuration"></a>
[Laravel 12] Explain redis: Clusters

If your application is utilizing a cluster of Redis servers, you should define these clusters within a clusters key of your Redis configuration. This configuration key does not exist by default so you will need to create it within your application's config/database.php configuration file:

By default, Laravel will use native Redis clustering since the options.cluster configuration value is set to redis. Redis clustering is a great default option, as it gracefully handles failover.

Laravel also supports client-side sharding when using Predis. However, client-side sharding does not handle failover; therefore, it is primarily suited for transient cached data that is available from another primary data store.

If you would like to use client-side sharding instead of native Redis clustering, you may remove the options.cluster configuration value within your application's config/database.php configuration file:

<a name="predis"></a>
[Laravel 12] Explain releases: Versioning Scheme

Laravel and its other first-party packages follow Semantic Versioning. Major framework releases are released every year (~Q1), while minor and patch releases may be released as often as every week. Minor and patch releases should **never** contain breaking changes.

When referencing the Laravel framework or its components from your application or package, you should always use a version constraint such as ^12.0, since major releases of Laravel do include breaking changes. However, we strive to always ensure you may update to a new major release in one day or less.

<a name="named-arguments"></a>
[Laravel 12] Explain releases: Support Policy

For all Laravel releases, bug fixes are provided for 18 months and security fixes are provided for 2 years. For all additional libraries, only the latest major release receives bug fixes. In addition, please review the database versions supported by Laravel.

<div class="overflow-auto">

| Version | PHP (*)   | Release             | Bug Fixes Until     | Security Fixes Until |
| ------- |-----------| ------------------- | ------------------- | -------------------- |
| 10      | 8.1 - 8.3 | February 14th, 2023 | August 6th, 2024    | February 4th, 2025   |
| 11      | 8.2 - 8.4 | March 12th, 2024    | September 3rd, 2025 | March 12th, 2026     |
| 12      | 8.2 - 8.5 | February 24th, 2025 | August 13th, 2026   | February 24th, 2027  |
| 13      | 8.3 - 8.5 | Q1 2026             | Q3 2027             | Q1 2028              |

</div>

<div class="version-colors">
    <div class="end-of-life">
        <div class="color-box"></div>
        <div>End of life</div>
    </div>
    <div class="security-fixes">
        <div class="color-box"></div>
        <div>Security fixes only</div>
    </div>
</div>

(*) Supported PHP versions

<a name="laravel-12"></a>
[Laravel 12] Explain requests: HTTP Requests

- Introduction
- Interacting With The Request
    - Accessing the Request
    - Request Path, Host, and Method
    - Request Headers
    - Request IP Address
    - Content Negotiation
    - PSR-7 Requests
- Input
    - Retrieving Input
    - Input Presence
    - Merging Additional Input
    - Old Input
    - Cookies
    - Input Trimming and Normalization
- Files
    - Retrieving Uploaded Files
    - Storing Uploaded Files
- Configuring Trusted Proxies
- Configuring Trusted Hosts

<a name="introduction"></a>
[Laravel 12] Explain requests: Accessing the Request

To obtain an instance of the current HTTP request via dependency injection, you should type-hint the Illuminate\Http\Request class on your route closure or controller method. The incoming request instance will automatically be injected by the Laravel service container:

As mentioned, you may also type-hint the Illuminate\Http\Request class on a route closure. The service container will automatically inject the incoming request into the closure when it is executed:

<a name="dependency-injection-route-parameters"></a>
[Laravel 12] Explain responses: HTTP Responses

- Creating Responses
    - Attaching Headers to Responses
    - Attaching Cookies to Responses
    - Cookies and Encryption
- Redirects
    - Redirecting to Named Routes
    - Redirecting to Controller Actions
    - Redirecting to External Domains
    - Redirecting With Flashed Session Data
- Other Response Types
    - View Responses
    - JSON Responses
    - File Downloads
    - File Responses
- Streamed Responses
    - Consuming Streamed Responses
    - Streamed JSON Responses
    - Event Streams (SSE)
    - Streamed Downloads
- Response Macros

<a name="creating-responses"></a>
[Laravel 12] Explain responses: Strings and Arrays

All routes and controllers should return a response to be sent back to the user's browser. Laravel provides several different ways to return responses. The most basic response is returning a string from a route or controller. The framework will automatically convert the string into a full HTTP response:

In addition to returning strings from your routes and controllers, you may also return arrays. The framework will automatically convert the array into a JSON response:

> [!NOTE]
> Did you know you can also return Eloquent collections from your routes or controllers? They will automatically be converted to JSON. Give it a shot!

<a name="response-objects"></a>
[Laravel 12] Explain responses: Response Objects

Typically, you won't just be returning simple strings or arrays from your route actions. Instead, you will be returning full Illuminate\Http\Response instances or views.

Returning a full Response instance allows you to customize the response's HTTP status code and headers. A Response instance inherits from the Symfony\Component\HttpFoundation\Response class, which provides a variety of methods for building HTTP responses:

<a name="eloquent-models-and-collections"></a>
[Laravel 12] Explain responses: Attaching Headers to Responses

Keep in mind that most response methods are chainable, allowing for the fluent construction of response instances. For example, you may use the header method to add a series of headers to the response before sending it back to the user:

Or, you may use the withHeaders method to specify an array of headers to be added to the response:

You can remove specific headers from an outgoing response using the withoutHeader method:

<a name="cache-control-middleware"></a>
[Laravel 12] Explain reverb: Laravel Reverb

- Introduction
- Installation
- Configuration
    - Application Credentials
    - Allowed Origins
    - Additional Applications
    - SSL
- Running the Server
    - Debugging
    - Restarting
- Monitoring
- Running Reverb in Production
    - Open Files
    - Event Loop
    - Web Server
    - Ports
    - Process Management
    - Scaling
- Events

<a name="introduction"></a>
[Laravel 12] Explain routing: Routing

- Basic Routing
    - The Default Route Files
    - Redirect Routes
    - View Routes
    - Listing Your Routes
    - Routing Customization
- Route Parameters
    - Required Parameters
    - Optional Parameters
    - Regular Expression Constraints
- Named Routes
- Route Groups
    - Middleware
    - Controllers
    - Subdomain Routing
    - Route Prefixes
    - Route Name Prefixes
- Route Model Binding
    - Implicit Binding
    - Implicit Enum Binding
    - Explicit Binding
- Fallback Routes
- Rate Limiting
    - Defining Rate Limiters
    - Attaching Rate Limiters to Routes
- Form Method Spoofing
- Accessing the Current Route
- Cross-Origin Resource Sharing (CORS)
- Route Caching

<a name="basic-routing"></a>
[Laravel 12] Explain routing: The Default Route Files

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by Laravel using the configuration specified in your application's bootstrap/app.php file. The routes/web.php file defines routes that are for your web interface. These routes are assigned the web middleware group, which provides features like session state and CSRF protection.

For most applications, you will begin by defining routes in your routes/web.php file. The routes defined in routes/web.php may be accessed by entering the defined route's URL in your browser. For example, you may access the following route by navigating to http://example.com/user in your browser:

<a name="api-routes"></a>
[Laravel 12] Explain routing: API Routes

If your application will also offer a stateless API, you may enable API routing using the install:api Artisan command:

The install:api command installs Laravel Sanctum, which provides a robust, yet simple API token authentication guard which can be used to authenticate third-party API consumers, SPAs, or mobile applications. In addition, the install:api command creates the routes/api.php file:

Of course, you are free to omit the auth:sanctum middleware on routes that should be publicly accessible.

The routes in routes/api.php are stateless and are assigned to the api middleware group. Additionally, the /api URI prefix is automatically applied to these routes, so you do not need to manually apply it to every route in the file. You may change the prefix by modifying your application's bootstrap/app.php file:

<a name="available-router-methods"></a>
[Laravel 12] Explain routing: Available Router Methods

The router allows you to register routes that respond to any HTTP verb:

Sometimes you may need to register a route that responds to multiple HTTP verbs. You may do so using the match method. Or, you may even register a route that responds to all HTTP verbs using the any method:

> [!NOTE]
> When defining multiple routes that share the same URI, routes using the get, post, put, patch, delete, and options methods should be defined before routes using the any, match, and redirect methods. This ensures the incoming request is matched with the correct route.

<a name="dependency-injection"></a>
[Laravel 12] Explain sail: Laravel Sail

- Introduction
- Installation and Setup
    - Installing Sail Into Existing Applications
    - Rebuilding Sail Images
    - Configuring A Shell Alias
- Starting and Stopping Sail
- Executing Commands
    - Executing PHP Commands
    - Executing Composer Commands
    - Executing Artisan Commands
    - Executing Node / NPM Commands
- Interacting With Databases
    - MySQL
    - MongoDB
    - Redis
    - Valkey
    - Meilisearch
    - Typesense
- File Storage
- Running Tests
    - Laravel Dusk
- Previewing Emails
- Container CLI
- PHP Versions
- Node Versions
- Sharing Your Site
- Debugging With Xdebug
  - Xdebug CLI Usage
  - Xdebug Browser Usage
- Customization

<a name="introduction"></a>
[Laravel 12] Explain sail: Introduction

Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.

At its heart, Sail is the compose.yaml file and the sail script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by the compose.yaml file.

Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).

<a name="installation"></a>
[Laravel 12] Explain sail: Installing Sail Into Existing Applications

If you are interested in using Sail with an existing Laravel application, you may simply install Sail using the Composer package manager. Of course, these steps assume that your existing local development environment allows you to install Composer dependencies:

After Sail has been installed, you may run the sail:install Artisan command. This command will publish Sail's compose.yaml file to the root of your application and modify your .env file with the required environment variables in order to connect to the Docker services:

Finally, you may start Sail. To continue learning how to use Sail, please continue reading the remainder of this documentation:

> [!WARNING]
> If you are using Docker Desktop for Linux, you should use the default Docker context by executing the following command: docker context use default. In addition, if you encounter file permission errors within containers, you may need to set the SUPERVISOR_PHP_USER environment variable to root.

<a name="adding-additional-services"></a>
[Laravel 12] Explain sanctum: Laravel Sanctum

- Introduction
    - How it Works
- Installation
- Configuration
    - Overriding Default Models
- API Token Authentication
    - Issuing API Tokens
    - Token Abilities
    - Protecting Routes
    - Revoking Tokens
    - Token Expiration
- SPA Authentication
    - Configuration
    - Authenticating
    - Protecting Routes
    - Authorizing Private Broadcast Channels
- Mobile Application Authentication
    - Issuing API Tokens
    - Protecting Routes
    - Revoking Tokens
- Testing

<a name="introduction"></a>
[Laravel 12] Explain sanctum: API Tokens

First, Sanctum is a simple package you may use to issue API tokens to your users without the complication of OAuth. This feature is inspired by GitHub and other applications which issue "personal access tokens". For example, imagine the "account settings" of your application has a screen where a user may generate an API token for their account. You may use Sanctum to generate and manage those tokens. These tokens typically have a very long expiration time (years), but may be manually revoked by the user anytime.

Laravel Sanctum offers this feature by storing user API tokens in a single database table and authenticating incoming HTTP requests via the Authorization header which should contain a valid API token.

<a name="how-it-works-spa-authentication"></a>