You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: eloquent-mutators.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ $user = User::find(1);
66
66
$firstName = $user->first_name;
67
67
```
68
68
69
-
> [!NOTE]
69
+
> [!NOTE]
70
70
> 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).
> 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.
> 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.
Copy file name to clipboardExpand all lines: eloquent-relationships.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -442,7 +442,7 @@ public function largestOrder(): HasOne
442
442
}
443
443
```
444
444
445
-
> [!WARNING]
445
+
> [!WARNING]
446
446
> 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.
> Intermediate tables that utilize Eloquent's automatically maintained timestamps are required to have both `created_at` and `updated_at` timestamp columns.
> 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.
@@ -1318,7 +1318,7 @@ public function bestImage(): MorphOne
1318
1318
}
1319
1319
```
1320
1320
1321
-
> [!NOTE]
1321
+
> [!NOTE]
1322
1322
> 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).
1323
1323
1324
1324
<aname="many-to-many-polymorphic-relations"></a>
@@ -1348,7 +1348,7 @@ taggables
1348
1348
taggable_type - string
1349
1349
```
1350
1350
1351
-
> [!NOTE]
1351
+
> [!NOTE]
1352
1352
> Before diving into polymorphic many-to-many relationships, you may benefit from reading the documentation on typical [many-to-many relationships](#many-to-many).
> 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.
1477
1477
1478
1478
<aname="dynamic-relationships"></a>
@@ -1491,7 +1491,7 @@ Order::resolveRelationUsing('customer', function (Order $orderModel) {
1491
1491
});
1492
1492
```
1493
1493
1494
-
> [!WARNING]
1494
+
> [!WARNING]
1495
1495
> When defining dynamic relationships, always provide explicit key name arguments to the Eloquent relationship methods.
You may also use the `findOrNew`, `firstOrNew`, `firstOrCreate`, and `updateOrCreate` methods to [create and update models on relationships](/docs/{{version}}/eloquent#upserts).
2360
2360
2361
-
> [!NOTE]
2361
+
> [!NOTE]
2362
2362
> Before using the `create` method, be sure to review the [mass assignment](/docs/{{version}}/eloquent#mass-assignment) documentation.
2363
2363
2364
2364
<aname="updating-belongs-to-relationships"></a>
@@ -2521,5 +2521,5 @@ class Comment extends Model
2521
2521
}
2522
2522
```
2523
2523
2524
-
> [!WARNING]
2524
+
> [!WARNING]
2525
2525
> Parent model timestamps will only be updated if the child model is updated using Eloquent's `save` method.
> 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.
49
49
50
50
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:
@@ -212,7 +212,7 @@ class UserCollection extends ResourceCollection
212
212
<aname="writing-resources"></a>
213
213
## Writing Resources
214
214
215
-
> [!NOTE]
215
+
> [!NOTE]
216
216
> If you have not read the [concept overview](#concept-overview), you are highly encouraged to do so before proceeding with this documentation.
217
217
218
218
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:
@@ -283,7 +283,7 @@ public function toArray(Request $request): array
283
283
}
284
284
```
285
285
286
-
> [!NOTE]
286
+
> [!NOTE]
287
287
> If you would like to include relationships only when they have already been loaded, check out the documentation on [conditional relationships](#conditional-relationships).
288
288
289
289
<aname="writing-resource-collections"></a>
@@ -392,7 +392,7 @@ class AppServiceProvider extends ServiceProvider
392
392
}
393
393
```
394
394
395
-
> [!WARNING]
395
+
> [!WARNING]
396
396
> The `withoutWrapping` method only affects the outermost response and will not remove `data` keys that you manually add to your own resource collections.
397
397
398
398
<aname="wrapping-nested-resources"></a>
@@ -605,7 +605,7 @@ public function toArray(Request $request): array
605
605
606
606
Again, if the given condition is `false`, these attributes will be removed from the resource response before it is sent to the client.
607
607
608
-
> [!WARNING]
608
+
> [!WARNING]
609
609
> 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.
Copy file name to clipboardExpand all lines: eloquent-serialization.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@
13
13
14
14
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.
15
15
16
-
> [!NOTE]
16
+
> [!NOTE]
17
17
> 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).
18
18
19
19
<aname="serializing-models-and-collections"></a>
@@ -105,7 +105,7 @@ class User extends Model
105
105
}
106
106
```
107
107
108
-
> [!NOTE]
108
+
> [!NOTE]
109
109
> To hide relationships, add the relationship's method name to your Eloquent model's `$hidden` property.
110
110
111
111
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:
Copy file name to clipboardExpand all lines: eloquent.md
+13-13
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@
44
44
45
45
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.
46
46
47
-
> [!NOTE]
47
+
> [!NOTE]
48
48
> 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).
> 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.
440
440
441
441
<aname="refreshing-models"></a>
@@ -558,7 +558,7 @@ Similar to the `lazy` method, the `cursor` method may be used to significantly r
558
558
559
559
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.
560
560
561
-
> [!WARNING]
561
+
> [!WARNING]
562
562
> 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.
563
563
564
564
Internally, the `cursor` method uses PHP [generators](https://www.php.net/manual/en/language.generators.overview.php) to implement this functionality:
@@ -807,7 +807,7 @@ Flight::where('active', 1)
807
807
808
808
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.
809
809
810
-
> [!WARNING]
810
+
> [!WARNING]
811
811
> 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.
> 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.
1017
1017
1018
1018
<aname="deleting-models"></a>
@@ -1049,7 +1049,7 @@ If you are utilizing [soft deleting models](#soft-deleting), you may permanently
1049
1049
Flight::forceDestroy(1);
1050
1050
```
1051
1051
1052
-
> [!WARNING]
1052
+
> [!WARNING]
1053
1053
> 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.
1054
1054
1055
1055
<aname="deleting-models-using-queries"></a>
@@ -1067,7 +1067,7 @@ To delete all models in a table, you should execute a query without adding any c
1067
1067
$deleted = Flight::query()->delete();
1068
1068
```
1069
1069
1070
-
> [!WARNING]
1070
+
> [!WARNING]
1071
1071
> 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.
1072
1072
1073
1073
<aname="soft-deleting"></a>
@@ -1089,7 +1089,7 @@ class Flight extends Model
1089
1089
}
1090
1090
```
1091
1091
1092
-
> [!NOTE]
1092
+
> [!NOTE]
1093
1093
> The `SoftDeletes` trait will automatically cast the `deleted_at` attribute to a `DateTime` / `Carbon` instance for you.
1094
1094
1095
1095
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:
@@ -1258,7 +1258,7 @@ You may test your `prunable` query by executing the `model:prune` command with t
1258
1258
php artisan model:prune --pretend
1259
1259
```
1260
1260
1261
-
> [!WARNING]
1261
+
> [!WARNING]
1262
1262
> Soft deleting models will be permanently deleted (`forceDelete`) if they match the prunable query.
1263
1263
1264
1264
<aname="mass-pruning"></a>
@@ -1371,7 +1371,7 @@ class AncientScope implements Scope
1371
1371
}
1372
1372
```
1373
1373
1374
-
> [!NOTE]
1374
+
> [!NOTE]
1375
1375
> 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.
1376
1376
1377
1377
<aname="applying-global-scopes"></a>
@@ -1628,7 +1628,7 @@ if ($post->author()->is($user)) {
1628
1628
<aname="events"></a>
1629
1629
## Events
1630
1630
1631
-
> [!NOTE]
1631
+
> [!NOTE]
1632
1632
> Want to broadcast your Eloquent events directly to your client-side application? Check out Laravel's [model event broadcasting](/docs/{{version}}/broadcasting#model-broadcasting).
1633
1633
1634
1634
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`.
@@ -1665,7 +1665,7 @@ class User extends Authenticatable
1665
1665
1666
1666
After defining and mapping your Eloquent events, you may use [event listeners](/docs/{{version}}/events#defining-listeners) to handle the events.
1667
1667
1668
-
> [!WARNING]
1668
+
> [!WARNING]
1669
1669
> 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.
1670
1670
1671
1671
<aname="events-using-closures"></a>
@@ -1797,7 +1797,7 @@ public function boot(): void
1797
1797
}
1798
1798
```
1799
1799
1800
-
> [!NOTE]
1800
+
> [!NOTE]
1801
1801
> There are additional events an observer can listen to, such as `saving` and `retrieved`. These events are described within the [events](#events) documentation.
Copy file name to clipboardExpand all lines: errors.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ When you register a custom exception reporting callback using the `report` metho
58
58
})
59
59
```
60
60
61
-
> [!NOTE]
61
+
> [!NOTE]
62
62
> To customize the exception reporting for a given exception, you may also utilize [reportable exceptions](/docs/{{version}}/errors#renderable-exceptions).
63
63
64
64
<aname="global-log-context"></a>
@@ -355,7 +355,7 @@ public function report(): bool
355
355
}
356
356
```
357
357
358
-
> [!NOTE]
358
+
> [!NOTE]
359
359
> 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).
Copy file name to clipboardExpand all lines: events.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -271,7 +271,7 @@ class SendShipmentNotification
271
271
}
272
272
```
273
273
274
-
> [!NOTE]
274
+
> [!NOTE]
275
275
> 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.
@@ -452,7 +452,7 @@ class SendShipmentNotification implements ShouldQueueAfterCommit
452
452
}
453
453
```
454
454
455
-
> [!NOTE]
455
+
> [!NOTE]
456
456
> 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).
457
457
458
458
<aname="handling-failed-jobs"></a>
@@ -539,7 +539,7 @@ public function retryUntil(): DateTime
539
539
#### Specifying Queued Listener Backoff
540
540
541
541
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:
542
-
542
+
543
543
```php
544
544
/**
545
545
* The number of seconds to wait before retrying the queued listener.
> 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.
> 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.
0 commit comments