SKILL.blade.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ---
  2. name: volt-development
  3. description: "Develops single-file Livewire components with Volt. Activates when creating Volt components, converting Livewire to Volt, working with @volt directive, functional or class-based Volt APIs; or when the user mentions Volt, single-file components, functional Livewire, or inline component logic in Blade files."
  4. license: MIT
  5. metadata:
  6. author: laravel
  7. ---
  8. @php
  9. /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
  10. @endphp
  11. # Volt Development
  12. ## Documentation
  13. Use `search-docs` for detailed Volt patterns and documentation.
  14. ## Basic Usage
  15. Create components with `{{ $assist->artisanCommand('make:volt [name] [--test] [--pest]') }}`.
  16. Important: Check existing Volt components to determine if they use functional or class-based style before creating new ones.
  17. ### Functional Components
  18. @boostsnippet("Volt Functional Component", "php")
  19. @@volt
  20. <?php
  21. use function Livewire\Volt\{state, computed};
  22. state(['count' => 0]);
  23. $increment = fn () => $this->count++;
  24. $double = computed(fn () => $this->count * 2);
  25. ?>
  26. <div>
  27. <h1>Count: @{{ $count }} (Double: @{{ $this->double }})</h1>
  28. <button wire:click="increment">+</button>
  29. </div>
  30. @@endvolt
  31. @endboostsnippet
  32. ### Class-Based Components
  33. @boostsnippet("Volt Class-based Component", "php")
  34. use Livewire\Volt\Component;
  35. new class extends Component {
  36. public int $count = 0;
  37. public function increment(): void
  38. {
  39. $this->count++;
  40. }
  41. } ?>
  42. <div>
  43. <h1>@{{ $count }}</h1>
  44. <button wire:click="increment">+</button>
  45. </div>
  46. @endboostsnippet
  47. ## Testing
  48. Tests go in existing Volt test directory or `tests/Feature/Volt`:
  49. @boostsnippet("Volt Test Example", "php")
  50. use Livewire\Volt\Volt;
  51. test('counter increments', function () {
  52. Volt::test('counter')
  53. ->assertSee('Count: 0')
  54. ->call('increment')
  55. ->assertSee('Count: 1');
  56. });
  57. @endboostsnippet
  58. ## Verification
  59. 1. Check existing components for functional vs class-based style
  60. 2. Test component with `Volt::test()`
  61. ## Common Pitfalls
  62. - Not checking existing style (functional vs class-based) before creating
  63. - Forgetting `@volt` directive wrapper
  64. - Missing `--test` or `--pest` flag when tests are needed