bhavin-gajjar/laravel-coder-lora-train huggingface dataset:
[Laravel 13] Explain database: Configuration Using URLs

Typically, database connections are configured using multiple configuration values such as host, database, username, password, etc. Each of these configuration values has its own corresponding environment variable. This means that when configuring your database connection information on a production server, you need to manage several environment variables.

Some managed database providers such as AWS and Heroku provide a single database "URL" that contains all of the connection information for the database in a single string. An example database URL may look something like the following:

These URLs typically follow a standard schema convention:

For convenience, Laravel supports these URLs as an alternative to configuring your database with multiple configuration options. If the url (or corresponding DB_URL environment variable) configuration option is present, it will be used to extract the database connection and credential information.

<a name="read-and-write-connections"></a>
[Laravel 13] Explain deployment: Deployment

- Introduction
- Server Requirements
- Server Configuration
    - Nginx
    - FrankenPHP
    - Directory Permissions
- Optimization
    - Caching Configuration
    - Caching Events
    - Caching Routes
    - Caching Views
- Reloading Services
- Debug Mode
- The Health Route
- Deploying With Laravel Cloud or Forge

<a name="introduction"></a>
[Laravel 13] Explain deployment: Server Requirements

The Laravel framework has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:

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

- PHP >= 8.3
- Ctype PHP Extension
- cURL PHP Extension
- DOM PHP Extension
- Fileinfo PHP Extension
- Filter PHP Extension
- Hash PHP Extension
- Mbstring PHP Extension
- OpenSSL PHP Extension
- PCRE PHP Extension
- PDO PHP Extension
- Session PHP Extension
- Tokenizer PHP Extension
- XML PHP Extension

</div>

<a name="server-configuration"></a>
[Laravel 13] Explain deployment: Nginx

If you are deploying your application to a server that is running Nginx, you may use the following configuration file as a starting point for configuring your web server. Most likely, this file will need to be customized depending on your server's configuration. **If you would like assistance in managing your server, consider using a fully-managed Laravel platform like Laravel Cloud.**

Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:

<a name="frankenphp"></a>
[Laravel 13] Explain deployment: FrankenPHP

FrankenPHP may also be used to serve your Laravel applications. FrankenPHP is a modern PHP application server written in Go. To serve a Laravel PHP application using FrankenPHP, you may simply invoke its php-server command:

To take advantage of more powerful features supported by FrankenPHP, such as its Laravel Octane integration, HTTP/3, modern compression, or the ability to package Laravel applications as standalone binaries, please consult FrankenPHP's Laravel documentation.

<a name="directory-permissions"></a>
[Laravel 13] Explain dusk: Laravel Dusk

- Introduction
- Installation
    - Managing ChromeDriver Installations
    - Using Other Browsers
- Getting Started
    - Generating Tests
    - Resetting the Database After Each Test
    - Running Tests
    - Environment Handling
- Browser Basics
    - Creating Browsers
    - Navigation
    - Resizing Browser Windows
    - Browser Macros
    - Authentication
    - Cookies
    - Executing JavaScript
    - Taking a Screenshot
    - Storing Console Output to Disk
    - Storing Page Source to Disk
- Interacting With Elements
    - Dusk Selectors
    - Text, Values, and Attributes
    - Interacting With Forms
    - Attaching Files
    - Pressing Buttons
    - Clicking Links
    - Using the Keyboard
    - Using the Mouse
    - JavaScript Dialogs
    - Interacting With Inline Frames
    - Scoping Selectors
    - Waiting for Elements
    - Scrolling an Element Into View
- Available Assertions
- Pages
    - Generating Pages
    - Configuring Pages
    - Navigating to Pages
    - Shorthand Selectors
    - Page Methods
- Components
    - Generating Components
    - Using Components
- Continuous Integration
    - Heroku CI
    - Travis CI
    - GitHub Actions
    - Chipper CI

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

> [!WARNING]
> Pest 4 now includes automated browser testing which offers significant performance and usability improvements compared to Laravel Dusk. For new projects, we recommend using Pest for browser testing.

Laravel Dusk provides an expressive, easy-to-use browser automation and testing API. By default, Dusk does not require you to install JDK or Selenium on your local computer. Instead, Dusk uses a standalone ChromeDriver installation. However, you are free to utilize any other Selenium compatible driver you wish.

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

To get started, you should install Google Chrome and add the laravel/dusk Composer dependency to your project:

> [!WARNING]
> If you are manually registering Dusk's service provider, you should **never** register it in your production environment, as doing so could lead to arbitrary users being able to authenticate with your application.

After installing the Dusk package, execute the dusk:install Artisan command. The dusk:install command will create a tests/Browser directory, an example Dusk test, and install the Chrome Driver binary for your operating system:

Next, set the APP_URL environment variable in your application's .env file. This value should match the URL you use to access your application in a browser.

> [!NOTE]
> If you are using Laravel Sail to manage your local development environment, please also consult the Sail documentation on configuring and running Dusk tests.

<a name="managing-chromedriver-installations"></a>
[Laravel 13] Explain dusk: Install the version of ChromeDriver that matches the detected version of Chrome / Chromium for your OS...

php artisan dusk:chrome-driver --detect
``

> [!WARNING]
> Dusk requires the chromedriver binaries to be executable. If you're having problems running Dusk, you should ensure the binaries are executable using the following command: chmod -R 0755 vendor/laravel/dusk/bin/`.

<a name="using-other-browsers"></a>
[Laravel 13] Explain dusk: Using Other Browsers

By default, Dusk uses Google Chrome and a standalone ChromeDriver installation to run your browser tests. However, you may start your own Selenium server and run your tests against any browser you wish.

To get started, open your tests/DuskTestCase.php file, which is the base Dusk test case for your application. Within this file, you can remove the call to the startChromeDriver method. This will stop Dusk from automatically starting the ChromeDriver:

Next, you may modify the driver method to connect to the URL and port of your choice. In addition, you may modify the "desired capabilities" that should be passed to the WebDriver:

<a name="getting-started"></a>
[Laravel 13] Explain eloquent collections: Introduction

All Eloquent methods that return more than one model result will return instances of the Illuminate\Database\Eloquent\Collection class, including results retrieved via the get method or accessed via a relationship. The Eloquent collection object extends Laravel's base collection, so it naturally inherits dozens of methods used to fluently work with the underlying array of Eloquent models. Be sure to review the Laravel collection documentation to learn all about these helpful methods!

All collections also serve as iterators, allowing you to loop over them as if they were simple PHP arrays:

However, as previously mentioned, collections are much more powerful than arrays and expose a variety of map / reduce operations that may be chained using an intuitive interface. For example, we may remove all inactive models and then gather the first name for each remaining user:

<a name="eloquent-collection-conversion"></a>
[Laravel 13] Explain eloquent collections: Available Methods

All Eloquent collections extend the base Laravel collection object; therefore, they inherit all of the powerful methods provided by the base collection class.

In addition, the Illuminate\Database\Eloquent\Collection class provides a superset of methods to aid with managing your model collections. Most methods return Illuminate\Database\Eloquent\Collection instances; however, some methods, like modelKeys, return an Illuminate\Support\Collection instance.

<style>
    .collection-method-list > p {
        columns: 14.4em 1; -moz-columns: 14.4em 1; -webkit-columns: 14.4em 1;
    }

    .collection-method-list a {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .collection-method code {
        font-size: 14px;
    }

    .collection-method:not(.first-collection-method) {
        margin-top: 50px;
    }
</style>

<div class="collection-method-list" markdown="1">

append
contains
diff
except
find
findOrFail
fresh
intersect
load
loadMissing
modelKeys
makeVisible
makeHidden
mergeVisible
mergeHidden
only
partition
setAppends
setVisible
setHidden
toQuery
unique
withoutAppends

</div>

<a name="method-append"></a>
[Laravel 13] Explain eloquent factories: Eloquent: Factories

- Introduction
- Defining Model Factories
    - Generating Factories
    - Factory States
    - Factory Callbacks
- Creating Models Using Factories
    - Instantiating Models
    - Persisting Models
    - Sequences
- Factory Relationships
    - Has Many Relationships
    - Belongs To Relationships
    - Many to Many Relationships
    - Polymorphic Relationships
    - Defining Relationships Within Factories
    - Recycling an Existing Model for Relationships

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

When testing your application or seeding your database, you may need to insert a few records into your database. Instead of manually specifying the value of each column, Laravel allows you to define a set of default attributes for each of your Eloquent models using model factories.

To see an example of how to write a factory, take a look at the database/factories/UserFactory.php file in your application. This factory is included with all new Laravel applications and contains the following factory definition:

As you can see, in their most basic form, factories are classes that extend Laravel's base factory class and define a definition method. The definition method returns the default set of attribute values that should be applied when creating a model using the factory.

Via the fake helper, factories have access to the Faker PHP library, which allows you to conveniently generate various kinds of random data for testing and seeding.

> [!NOTE]
> You can change your application's Faker locale by updating the faker_locale option in your config/app.php configuration file.

<a name="defining-model-factories"></a>
[Laravel 13] Explain eloquent factories: Model and Factory Discovery Conventions

Once you have defined your factories, you may use the static factory method provided to your models by the Illuminate\Database\Eloquent\Factories\HasFactory trait in order to instantiate a factory instance for that model.

The HasFactory trait's factory method will use conventions to determine the proper factory for the model the trait is assigned to. Specifically, the method will look for a factory in the Database\Factories namespace that has a class name matching the model name and is suffixed with Factory. If these conventions do not apply to your particular application or factory, you may add the UseFactory attribute to the model to manually specify the model's factory:

```php
use Illuminate\Database\Eloquent\Attributes\UseFactory;
use Database\Factories\Administration\FlightFactory;
[Laravel 13] Explain eloquent factories: [UseFactory(FlightFactory::class)]

class Flight extends Model
{
    // ...
}
php
use Database\Factories\Administration\FlightFactory;

/**
 * Create a new factory instance for the model.
 */
protected static function newFactory()
{
    return FlightFactory::new();
}
php
use App\Administration\Flight;
use Illuminate\Database\Eloquent\Factories\Attributes\UseModel;
use Illuminate\Database\Eloquent\Factories\Factory;
[Laravel 13] Explain eloquent mutators: Eloquent: Mutators & Casting

- Introduction
- Accessors and Mutators
    - Defining an Accessor
    - Defining a Mutator
- Attribute Casting
    - Array and JSON Casting
    - Binary Casting
    - Date Casting
    - Enum Casting
    - Encrypted Casting
    - Query Time Casting
- Custom Casts
    - Value Object Casting
    - Array / JSON Serialization
    - Inbound Casting
    - Cast Parameters
    - Comparing Cast Values
    - Castables

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

Accessors, mutators, and attribute casting allow you to transform Eloquent attribute values when you retrieve or set them on model instances. For example, you may want to use the Laravel encrypter to encrypt a value while it is stored in the database, and then automatically decrypt the attribute when you access it on an Eloquent model. Or, you may want to convert a JSON string that is stored in your database to an array when it is accessed via your Eloquent model.

<a name="accessors-and-mutators"></a>
[Laravel 13] Explain eloquent mutators: Defining an Accessor

An accessor transforms an Eloquent attribute value when it is accessed. To define an accessor, create a protected method on your model to represent the accessible attribute. This method name should correspond to the "camel case" representation of the true underlying model attribute / database column when applicable.

In this example, we'll define an accessor for the first_name attribute. The accessor will automatically be called by Eloquent when attempting to retrieve the value of the first_name attribute. All attribute accessor / mutator methods must declare a return type-hint of Illuminate\Database\Eloquent\Casts\Attribute:

All accessor methods return an Attribute instance which defines how the attribute will be accessed and, optionally, mutated. In this example, we are only defining how the attribute will be accessed. To do so, we supply the get argument to the Attribute class constructor.

As you can see, the original value of the column is passed to the accessor, allowing you to manipulate and return the value. To access the value of the accessor, you may simply access the first_name attribute on a model instance:

> [!NOTE]
> If you would like these computed values to be added to the array / JSON representations of your model, you will need to append them.

<a name="building-value-objects-from-multiple-attributes"></a>
[Laravel 13] Explain eloquent mutators: Accessor Caching

When returning value objects from accessors, any changes made to the value object will automatically be synced back to the model before the model is saved. This is possible because Eloquent retains instances returned by accessors so it can return the same instance each time the accessor is invoked:

However, you may sometimes wish to enable caching for primitive values like strings and booleans, particularly if they are computationally intensive. To accomplish this, you may invoke the shouldCache method when defining your accessor:

If you would like to disable the object caching behavior of attributes, you may invoke the withoutObjectCaching method when defining the attribute:

<a name="defining-a-mutator"></a>
[Laravel 13] Explain eloquent mutators: Defining a Mutator

A mutator transforms an Eloquent attribute value when it is set. To define a mutator, you may provide the set argument when defining your attribute. Let's define a mutator for the first_name attribute. This mutator will be automatically called when we attempt to set the value of the first_name attribute on the model:

The mutator closure will receive the value that is being set on the attribute, allowing you to manipulate the value and return the manipulated value. To use our mutator, we only need to set the first_name attribute on an Eloquent model:

In this example, the set callback will be called with the value Sally. The mutator will then apply the strtolower function to the name and set its resulting value in the model's internal $attributes array.

<a name="mutating-multiple-attributes"></a>
[Laravel 13] Explain eloquent relationships: Eloquent: Relationships

- Introduction
- Defining Relationships
    - One to One / Has One
    - One to Many / Has Many
    - One to Many (Inverse) / Belongs To
    - Has One of Many
    - Has One Through
    - Has Many Through
- Scoped Relationships
- Many to Many Relationships
    - Retrieving Intermediate Table Columns
    - Filtering Queries via Intermediate Table Columns
    - Ordering Queries via Intermediate Table Columns
    - Defining Custom Intermediate Table Models
- Polymorphic Relationships
    - One to One
    - One to Many
    - One of Many
    - Many to Many
    - Custom Polymorphic Types
- Dynamic Relationships
- Querying Relations
    - Relationship Methods vs. Dynamic Properties
    - Querying Relationship Existence
    - Querying Relationship Absence
    - Querying Morph To Relationships
- Aggregating Related Models
    - Counting Related Models
    - Other Aggregate Functions
    - Counting Related Models on Morph To Relationships
- Eager Loading
    - Constraining Eager Loads
    - Lazy Eager Loading
    - Automatic Eager Loading
    - Preventing Lazy Loading
- Inserting and Updating Related Models
    - The save Method
    - The create Method
    - Belongs To Relationships
    - Many to Many Relationships
- Touching Parent Timestamps

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

Database tables are often related to one another. For example, a blog post may have many comments or an order could be related to the user who placed it. Eloquent makes managing and working with these relationships easy, and supports a variety of common relationships:

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

- One To One
- One To Many
- Many To Many
- Has One Through
- Has Many Through
- One To One (Polymorphic)
- One To Many (Polymorphic)
- Many To Many (Polymorphic)

</div>

<a name="defining-relationships"></a>
[Laravel 13] Explain eloquent relationships: Defining Relationships

Eloquent relationships are defined as methods on your Eloquent model classes. Since relationships also serve as powerful query builders, defining relationships as methods provides powerful method chaining and querying capabilities. For example, we may chain additional query constraints on this posts relationship:

But, before diving too deep into using relationships, let's learn how to define each type of relationship supported by Eloquent.

<a name="one-to-one"></a>
[Laravel 13] Explain eloquent relationships: One to One / Has One

A one-to-one relationship is a very basic type of database relationship. For example, a User model might be associated with one Phone model. To define this relationship, we will place a phone method on the User model. The phone method should call the hasOne method and return its result. The hasOne method is available to your model via the model's Illuminate\Database\Eloquent\Model base class:

The first argument passed to the hasOne method is the name of the related model class. Once the relationship is defined, we may retrieve the related record using Eloquent's dynamic properties. Dynamic properties allow you to access relationship methods as if they were properties defined on the model:

Eloquent determines the foreign key of the relationship based on the parent model name. In this case, the Phone model is automatically assumed to have a user_id foreign key. If you wish to override this convention, you may pass a second argument to the hasOne method:

Additionally, Eloquent assumes that the foreign key should have a value matching the primary key column of the parent. In other words, Eloquent will look for the value of the user's id column in the user_id column of the Phone record. If you would like the relationship to use a primary key value other than id or your model's primary key, you may pass a third argument to the hasOne method:

<a name="one-to-one-defining-the-inverse-of-the-relationship"></a>
[Laravel 13] Explain eloquent relationships: Defining the Inverse of the Relationship

So, we can access the Phone model from our User model. Next, let's define a relationship on the Phone model that will let us access the user that owns the phone. We can define the inverse of a hasOne relationship using the belongsTo method:

When invoking the user method, Eloquent will attempt to find a User model that has an id which matches the user_id column on the Phone model.

Eloquent determines the foreign key name by examining the name of the relationship method and suffixing the method name with _id. So, in this case, Eloquent assumes that the Phone model has a user_id column. However, if the foreign key on the Phone model is not user_id, you may pass a custom key name as the second argument to the belongsTo method:

If the parent model does not use id as its primary key, or you wish to find the associated model using a different column, you may pass a third argument to the belongsTo method specifying the parent table's custom key:

<a name="one-to-many"></a>
[Laravel 13] Explain eloquent relationships: One to Many / Has Many

A one-to-many relationship is used to define relationships where a single model is the parent to one or more child models. For example, a blog post may have an infinite number of comments. Like all other Eloquent relationships, one-to-many relationships are defined by defining a method on your Eloquent model:

Remember, Eloquent will automatically determine the proper foreign key column for the Comment model. By convention, Eloquent will take the "snake case" name of the parent model and suffix it with _id. So, in this example, Eloquent will assume the foreign key column on the Comment model is post_id.

Once the relationship method has been defined, we can access the collection of related comments by accessing the comments property. Remember, since Eloquent provides "dynamic relationship properties", we can access relationship methods as if they were defined as properties on the model:

Since all relationships also serve as query builders, you may add further constraints to the relationship query by calling the comments method and continuing to chain conditions onto the query:

Like the hasOne method, you may also override the foreign and local keys by passing additional arguments to the hasMany method:

<a name="automatically-hydrating-parent-models-on-children"></a>
[Laravel 13] Explain eloquent resources: Eloquent: API Resources

- Introduction
- Generating Resources
- Concept Overview
    - Resource Collections
- Writing Resources
    - Data Wrapping
    - Pagination
    - Conditional Attributes
    - Conditional Relationships
    - Adding Meta Data
- JSON:API Resources
    - Generating JSON:API Resources
    - Defining Attributes
    - Defining Relationships
    - Resource Type and ID
    - Sparse Fieldsets and Includes
    - Links and Meta
- Resource Responses

<a name="introduction"></a>