Update dependencies
Composer: Laravel 13.43, Octane 2.25, Fortify 1.43 and Pest 5.3.7, with the packages they bring (70 in all). This fixes the advisories in Laravel and the Symfony components. npm: Vite 8.3.8 with Rolldown 1.2.19, Playwright 1.65.1 and chokidar 6. The asset build, CI and the dev container use Node.js 26. The dev image also has git for Composer. Both audits are clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Blade and View Best Practices
|
||||
# Blade and view best practices
|
||||
|
||||
## Use `$attributes->merge()` in Component Templates
|
||||
## Use `$attributes->merge()` in component templates
|
||||
|
||||
Use the component attribute bag so callers can add attributes. `merge()` combines default attributes with caller-provided values; class values receive special merging behavior.
|
||||
Use the component attribute bag so callers can add attributes. `merge()` combines default attributes with caller-provided values. Class values receive special merging behavior.
|
||||
|
||||
```blade
|
||||
<div {{ $attributes->merge(['class' => 'alert alert-'.$type]) }}>
|
||||
@@ -10,19 +10,19 @@ Use the component attribute bag so callers can add attributes. `merge()` combine
|
||||
</div>
|
||||
```
|
||||
|
||||
## Use `@pushOnce` for Per-Component Scripts
|
||||
## Use `@pushOnce` for per-component scripts
|
||||
|
||||
If a component renders repeatedly, `@push` adds its script on every render. Use a consistently named `@pushOnce` block to add that content once per rendered response.
|
||||
|
||||
## Prefer Components for Explicit Interfaces
|
||||
## Prefer components for explicit interfaces
|
||||
|
||||
Use a Blade component when a reusable interface benefits from explicit props, an attribute bag, or slots. An include remains suitable for a small partial that intentionally uses the current view data; pass an explicit data array when implicit variable sharing would obscure its dependencies.
|
||||
Use a Blade component when a reusable interface benefits from explicit props, an attribute bag, or slots. An include still suits a small partial that intentionally uses the current view data. Pass an explicit data array when implicit variable sharing would hide the partial's dependencies.
|
||||
|
||||
## Share Compatible View Data with a View Composer
|
||||
## Share compatible view data with a view composer
|
||||
|
||||
Use a view composer to centralize data needed whenever one or more named Blade views are rendered. Keep the composer compatible with every view it targets, and avoid broad wildcards when views require different data shapes. A view composer runs when Laravel renders the matching view; it does not supply data to JSON, streamed, or other non-view responses.
|
||||
Use a view composer to centralize the data that one or more named Blade views need every time Laravel renders them. Keep the composer compatible with every view it targets, and avoid broad wildcards when views require different data shapes. A view composer runs when Laravel renders the matching view. It does not supply data to JSON, streamed, or other non-view responses.
|
||||
|
||||
## Return Blade Fragments for Partial Rendering
|
||||
## Return Blade fragments for partial rendering
|
||||
|
||||
A route can return either a full view or a named fragment for clients such as htmx or Turbo.
|
||||
|
||||
@@ -31,6 +31,6 @@ return view('dashboard', compact('users'))
|
||||
->fragmentIf($request->hasHeader('HX-Request'), 'user-list');
|
||||
```
|
||||
|
||||
## Share Parent Component Props with `@aware`
|
||||
## Share parent component props with `@aware`
|
||||
|
||||
Use `@aware` when a nested component needs a prop explicitly passed to an ancestor component. It does not expose an ancestor's default prop value unless that value was passed through the attribute bag.
|
||||
Use `@aware` when a nested component needs a prop explicitly passed to an ancestor component. `@aware` does not expose an ancestor's default prop value unless that value was passed through the attribute bag.
|
||||
|
||||
Reference in New Issue
Block a user