Skip to content

[12.x] Fix markdown formatting #10259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eloquent-mutators.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $user = User::find(1);
$firstName = $user->first_name;
```

> [!NOTE]
> [!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](/docs/{{version}}/eloquent-serialization#appending-values-to-json).

<a name="building-value-objects-from-multiple-attributes"></a>
Expand Down Expand Up @@ -280,7 +280,7 @@ $user->mergeCasts([
]);
```

> [!WARNING]
> [!WARNING]
> Attributes that are `null` will not be cast. In addition, you should never define a cast (or an attribute) that has the same name as a relationship or assign a cast to the model's primary key.

<a name="stringable-casting"></a>
Expand Down Expand Up @@ -710,7 +710,7 @@ $user->address->lineOne = 'Updated Address Value';
$user->save();
```

> [!NOTE]
> [!NOTE]
> If you plan to serialize your Eloquent models containing value objects to JSON or arrays, you should implement the `Illuminate\Contracts\Support\Arrayable` and `JsonSerializable` interfaces on the value object.

<a name="value-object-caching"></a>
Expand Down
22 changes: 11 additions & 11 deletions eloquent-relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function largestOrder(): HasOne
}
```

> [!WARNING]
> [!WARNING]
> Because PostgreSQL does not support executing the `MAX` function against UUID columns, it is not currently possible to use one-of-many relationships in combination with PostgreSQL UUID columns.

<a name="converting-many-relationships-to-has-one-relationships"></a>
Expand Down Expand Up @@ -870,7 +870,7 @@ If you would like your intermediate table to have `created_at` and `updated_at`
return $this->belongsToMany(Role::class)->withTimestamps();
```

> [!WARNING]
> [!WARNING]
> Intermediate tables that utilize Eloquent's automatically maintained timestamps are required to have both `created_at` and `updated_at` timestamp columns.

<a name="customizing-the-pivot-attribute-name"></a>
Expand Down Expand Up @@ -988,7 +988,7 @@ class RoleUser extends Pivot
}
```

> [!WARNING]
> [!WARNING]
> Pivot models may not use the `SoftDeletes` trait. If you need to soft delete pivot records consider converting your pivot model to an actual Eloquent model.

<a name="custom-pivot-models-and-incrementing-ids"></a>
Expand Down Expand Up @@ -1318,7 +1318,7 @@ public function bestImage(): MorphOne
}
```

> [!NOTE]
> [!NOTE]
> It is possible to construct more advanced "one of many" relationships. For more information, please consult the [has one of many documentation](#advanced-has-one-of-many-relationships).

<a name="many-to-many-polymorphic-relations"></a>
Expand Down Expand Up @@ -1348,7 +1348,7 @@ taggables
taggable_type - string
```

> [!NOTE]
> [!NOTE]
> Before diving into polymorphic many-to-many relationships, you may benefit from reading the documentation on typical [many-to-many relationships](#many-to-many).

<a name="many-to-many-polymorphic-model-structure"></a>
Expand Down Expand Up @@ -1472,7 +1472,7 @@ $alias = $post->getMorphClass();
$class = Relation::getMorphedModel($alias);
```

> [!WARNING]
> [!WARNING]
> When adding a "morph map" to your existing application, every morphable `*_type` column value in your database that still contains a fully-qualified class will need to be converted to its "map" name.

<a name="dynamic-relationships"></a>
Expand All @@ -1491,7 +1491,7 @@ Order::resolveRelationUsing('customer', function (Order $orderModel) {
});
```

> [!WARNING]
> [!WARNING]
> When defining dynamic relationships, always provide explicit key name arguments to the Eloquent relationship methods.

<a name="querying-relations"></a>
Expand Down Expand Up @@ -1633,7 +1633,7 @@ $posts = Post::whereHas('comments', function (Builder $query) {
}, '>=', 10)->get();
```

> [!WARNING]
> [!WARNING]
> Eloquent does not currently support querying for relationship existence across databases. The relationships must exist within the same database.

<a name="inline-relationship-existence-queries"></a>
Expand Down Expand Up @@ -2041,7 +2041,7 @@ You may not always need every column from the relationships you are retrieving.
$books = Book::with('author:id,name,book_id')->get();
```

> [!WARNING]
> [!WARNING]
> When using this feature, you should always include the `id` column and any relevant foreign key columns in the list of columns you wish to retrieve.

<a name="eager-loading-by-default"></a>
Expand Down Expand Up @@ -2358,7 +2358,7 @@ $user->posts()->createManyQuietly([

You may also use the `findOrNew`, `firstOrNew`, `firstOrCreate`, and `updateOrCreate` methods to [create and update models on relationships](/docs/{{version}}/eloquent#upserts).

> [!NOTE]
> [!NOTE]
> Before using the `create` method, be sure to review the [mass assignment](/docs/{{version}}/eloquent#mass-assignment) documentation.

<a name="updating-belongs-to-relationships"></a>
Expand Down Expand Up @@ -2521,5 +2521,5 @@ class Comment extends Model
}
```

> [!WARNING]
> [!WARNING]
> Parent model timestamps will only be updated if the child model is updated using Eloquent's `save` method.
10 changes: 5 additions & 5 deletions eloquent-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ php artisan make:resource UserCollection
<a name="concept-overview"></a>
## Concept Overview

> [!NOTE]
> [!NOTE]
> This is a high-level overview of resources and resource collections. You are highly encouraged to read the other sections of this documentation to gain a deeper understanding of the customization and power offered to you by resources.

Before diving into all of the options available to you when writing resources, let's first take a high-level look at how resources are used within Laravel. A resource class represents a single model that needs to be transformed into a JSON structure. For example, here is a simple `UserResource` resource class:
Expand Down Expand Up @@ -212,7 +212,7 @@ class UserCollection extends ResourceCollection
<a name="writing-resources"></a>
## Writing Resources

> [!NOTE]
> [!NOTE]
> If you have not read the [concept overview](#concept-overview), you are highly encouraged to do so before proceeding with this documentation.

Resources only need to transform a given model into an array. So, each resource contains a `toArray` method which translates your model's attributes into an API friendly array that can be returned from your application's routes or controllers:
Expand Down Expand Up @@ -283,7 +283,7 @@ public function toArray(Request $request): array
}
```

> [!NOTE]
> [!NOTE]
> If you would like to include relationships only when they have already been loaded, check out the documentation on [conditional relationships](#conditional-relationships).

<a name="writing-resource-collections"></a>
Expand Down Expand Up @@ -392,7 +392,7 @@ class AppServiceProvider extends ServiceProvider
}
```

> [!WARNING]
> [!WARNING]
> The `withoutWrapping` method only affects the outermost response and will not remove `data` keys that you manually add to your own resource collections.

<a name="wrapping-nested-resources"></a>
Expand Down Expand Up @@ -605,7 +605,7 @@ public function toArray(Request $request): array

Again, if the given condition is `false`, these attributes will be removed from the resource response before it is sent to the client.

> [!WARNING]
> [!WARNING]
> The `mergeWhen` method should not be used within arrays that mix string and numeric keys. Furthermore, it should not be used within arrays with numeric keys that are not ordered sequentially.

<a name="conditional-relationships"></a>
Expand Down
4 changes: 2 additions & 2 deletions eloquent-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

When building APIs using Laravel, you will often need to convert your models and relationships to arrays or JSON. Eloquent includes convenient methods for making these conversions, as well as controlling which attributes are included in the serialized representation of your models.

> [!NOTE]
> [!NOTE]
> For an even more robust way of handling Eloquent model and collection JSON serialization, check out the documentation on [Eloquent API resources](/docs/{{version}}/eloquent-resources).

<a name="serializing-models-and-collections"></a>
Expand Down Expand Up @@ -105,7 +105,7 @@ class User extends Model
}
```

> [!NOTE]
> [!NOTE]
> To hide relationships, add the relationship's method name to your Eloquent model's `$hidden` property.

Alternatively, you may use the `visible` property to define an "allow list" of attributes that should be included in your model's array and JSON representation. All attributes that are not present in the `$visible` array will be hidden when the model is converted to an array or JSON:
Expand Down
26 changes: 13 additions & 13 deletions eloquent.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

Laravel includes Eloquent, an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using Eloquent, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, Eloquent models allow you to insert, update, and delete records from the table as well.

> [!NOTE]
> [!NOTE]
> Before getting started, be sure to configure a database connection in your application's `config/database.php` configuration file. For more information on configuring your database, check out [the database configuration documentation](/docs/{{version}}/database#configuration).

<a name="generating-model-classes"></a>
Expand Down Expand Up @@ -435,7 +435,7 @@ $flights = Flight::where('active', 1)
->get();
```

> [!NOTE]
> [!NOTE]
> Since Eloquent models are query builders, you should review all of the methods provided by Laravel's [query builder](/docs/{{version}}/queries). You may use any of these methods when writing your Eloquent queries.

<a name="refreshing-models"></a>
Expand Down Expand Up @@ -558,7 +558,7 @@ Similar to the `lazy` method, the `cursor` method may be used to significantly r

The `cursor` method will only execute a single database query; however, the individual Eloquent models will not be hydrated until they are actually iterated over. Therefore, only one Eloquent model is kept in memory at any given time while iterating over the cursor.

> [!WARNING]
> [!WARNING]
> Since the `cursor` method only ever holds a single Eloquent model in memory at a time, it cannot eager load relationships. If you need to eager load relationships, consider using [the `lazy` method](#chunking-using-lazy-collections) instead.

Internally, the `cursor` method uses PHP [generators](https://www.php.net/manual/en/language.generators.overview.php) to implement this functionality:
Expand Down Expand Up @@ -807,7 +807,7 @@ Flight::where('active', 1)

The `update` method expects an array of column and value pairs representing the columns that should be updated. The `update` method returns the number of affected rows.

> [!WARNING]
> [!WARNING]
> When issuing a mass update via Eloquent, the `saving`, `saved`, `updating`, and `updated` model events will not be fired for the updated models. This is because the models are never actually retrieved when issuing a mass update.

<a name="examining-attribute-changes"></a>
Expand Down Expand Up @@ -1012,7 +1012,7 @@ Flight::upsert([
], uniqueBy: ['departure', 'destination'], update: ['price']);
```

> [!WARNING]
> [!WARNING]
> All databases except SQL Server require the columns in the second argument of the `upsert` method to have a "primary" or "unique" index. In addition, the MariaDB and MySQL database drivers ignore the second argument of the `upsert` method and always use the "primary" and "unique" indexes of the table to detect existing records.

<a name="deleting-models"></a>
Expand Down Expand Up @@ -1049,7 +1049,7 @@ If you are utilizing [soft deleting models](#soft-deleting), you may permanently
Flight::forceDestroy(1);
```

> [!WARNING]
> [!WARNING]
> The `destroy` method loads each model individually and calls the `delete` method so that the `deleting` and `deleted` events are properly dispatched for each model.

<a name="deleting-models-using-queries"></a>
Expand All @@ -1067,7 +1067,7 @@ To delete all models in a table, you should execute a query without adding any c
$deleted = Flight::query()->delete();
```

> [!WARNING]
> [!WARNING]
> When executing a mass delete statement via Eloquent, the `deleting` and `deleted` model events will not be dispatched for the deleted models. This is because the models are never actually retrieved when executing the delete statement.

<a name="soft-deleting"></a>
Expand All @@ -1089,7 +1089,7 @@ class Flight extends Model
}
```

> [!NOTE]
> [!NOTE]
> The `SoftDeletes` trait will automatically cast the `deleted_at` attribute to a `DateTime` / `Carbon` instance for you.

You should also add the `deleted_at` column to your database table. The Laravel [schema builder](/docs/{{version}}/migrations) contains a helper method to create this column:
Expand Down Expand Up @@ -1258,7 +1258,7 @@ You may test your `prunable` query by executing the `model:prune` command with t
php artisan model:prune --pretend
```

> [!WARNING]
> [!WARNING]
> Soft deleting models will be permanently deleted (`forceDelete`) if they match the prunable query.

<a name="mass-pruning"></a>
Expand Down Expand Up @@ -1371,7 +1371,7 @@ class AncientScope implements Scope
}
```

> [!NOTE]
> [!NOTE]
> If your global scope is adding columns to the select clause of the query, you should use the `addSelect` method instead of `select`. This will prevent the unintentional replacement of the query's existing select clause.

<a name="applying-global-scopes"></a>
Expand Down Expand Up @@ -1628,7 +1628,7 @@ if ($post->author()->is($user)) {
<a name="events"></a>
## Events

> [!NOTE]
> [!NOTE]
> Want to broadcast your Eloquent events directly to your client-side application? Check out Laravel's [model event broadcasting](/docs/{{version}}/broadcasting#model-broadcasting).

Eloquent models dispatch several events, allowing you to hook into the following moments in a model's lifecycle: `retrieved`, `creating`, `created`, `updating`, `updated`, `saving`, `saved`, `deleting`, `deleted`, `trashed`, `forceDeleting`, `forceDeleted`, `restoring`, `restored`, and `replicating`.
Expand Down Expand Up @@ -1665,7 +1665,7 @@ class User extends Authenticatable

After defining and mapping your Eloquent events, you may use [event listeners](/docs/{{version}}/events#defining-listeners) to handle the events.

> [!WARNING]
> [!WARNING]
> When issuing a mass update or delete query via Eloquent, the `saved`, `updated`, `deleting`, and `deleted` model events will not be dispatched for the affected models. This is because the models are never actually retrieved when performing mass updates or deletes.

<a name="events-using-closures"></a>
Expand Down Expand Up @@ -1797,7 +1797,7 @@ public function boot(): void
}
```

> [!NOTE]
> [!NOTE]
> There are additional events an observer can listen to, such as `saving` and `retrieved`. These events are described within the [events](#events) documentation.

<a name="observers-and-database-transactions"></a>
Expand Down
4 changes: 2 additions & 2 deletions errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ When you register a custom exception reporting callback using the `report` metho
})
```

> [!NOTE]
> [!NOTE]
> To customize the exception reporting for a given exception, you may also utilize [reportable exceptions](/docs/{{version}}/errors#renderable-exceptions).

<a name="global-log-context"></a>
Expand Down Expand Up @@ -355,7 +355,7 @@ public function report(): bool
}
```

> [!NOTE]
> [!NOTE]
> You may type-hint any required dependencies of the `report` method and they will automatically be injected into the method by Laravel's [service container](/docs/{{version}}/container).

<a name="throttling-reported-exceptions"></a>
Expand Down
10 changes: 5 additions & 5 deletions events.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class SendShipmentNotification
}
```

> [!NOTE]
> [!NOTE]
> Your event listeners may also type-hint any dependencies they need on their constructors. All event listeners are resolved via the Laravel [service container](/docs/{{version}}/container), so dependencies will be injected automatically.

<a name="stopping-the-propagation-of-an-event"></a>
Expand Down Expand Up @@ -452,7 +452,7 @@ class SendShipmentNotification implements ShouldQueueAfterCommit
}
```

> [!NOTE]
> [!NOTE]
> To learn more about working around these issues, please review the documentation regarding [queued jobs and database transactions](/docs/{{version}}/queues#jobs-and-database-transactions).

<a name="handling-failed-jobs"></a>
Expand Down Expand Up @@ -539,7 +539,7 @@ public function retryUntil(): DateTime
#### Specifying Queued Listener Backoff

If you would like to configure how many seconds Laravel should wait before retrying a listener that has encountered an exception, you may do so by defining a `backoff` property on your listener class:

```php
/**
* The number of seconds to wait before retrying the queued listener.
Expand Down Expand Up @@ -616,7 +616,7 @@ OrderShipped::dispatchIf($condition, $order);
OrderShipped::dispatchUnless($condition, $order);
```

> [!NOTE]
> [!NOTE]
> When testing, it can be helpful to assert that certain events were dispatched without actually triggering their listeners. Laravel's [built-in testing helpers](#testing) make it a cinch.

<a name="dispatching-events-after-database-transactions"></a>
Expand Down Expand Up @@ -847,7 +847,7 @@ Event::assertListening(
);
```

> [!WARNING]
> [!WARNING]
> After calling `Event::fake()`, no event listeners will be executed. So, if your tests use model factories that rely on events, such as creating a UUID during a model's `creating` event, you should call `Event::fake()` **after** using your factories.

<a name="faking-a-subset-of-events"></a>
Expand Down
Loading