-
Notifications
You must be signed in to change notification settings - Fork 223
/
making-components.blade.php
69 lines (49 loc) · 1.84 KB
/
making-components.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
* [Introduction](#introduction)
* [Inline Components](#inline-components)
## Introduction {#introduction}
Run the following artisan command to create a new Livewire component:
@component('components.code', ['lang' => 'shell'])
php artisan make:livewire ShowPosts
@endcomponent
Livewire also supports "kebab" notation for new components.
@component('components.code', ['lang' => 'shell'])
php artisan make:livewire show-posts
@endcomponent
Two new files were created in your project:
* `app/Http/Livewire/ShowPosts.php`
* `resources/views/livewire/show-posts.blade.php`
If you wish to create components within sub-folders, you can use the following different syntaxes:
@component('components.code', ['lang' => 'shell'])
php artisan make:livewire Post\\Show
php artisan make:livewire Post/Show
php artisan make:livewire post.show
@endcomponent
Now, the two created files will be in sub-folders:
* `app/Http/Livewire/Post/Show.php`
* `resources/views/livewire/post/show.blade.php`
### Generating Tests {#generating-tests}
Optionally, you can include the `--test` flag when creating a component, and a test file will be created for you as well.
@component('components.code', ['lang' => 'shell'])
php artisan make:livewire ShowPosts --test
@endcomponent
## Inline Components {#inline-components}
If you wish to create Inline components (Components without `.blade.php` files), you can add the `--inline` flag to the command:
@component('components.code', ['lang' => 'shell'])
php artisan make:livewire ShowPosts --inline
@endcomponent
Now, only one file will be created:
* `app/Http/Livewire/ShowPosts.php`
Here's what it would look like:
@component('components.code', ['lang' => 'php'])
@verbatim
class ShowPosts extends Component
{
public function render()
{
return <<<'blade'
<div></div>
blade;
}
}
@endverbatim
@endcomponent