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
With this artisan command a UsersTableView.php file will be created inside the `app/Http/Livewire` directory.
77
77
78
-
The basic usage needs a data repository (Eloquent query), headers and rows, you can customize the items to be shown, and the headers and data for each row like this example
78
+
The basic usage needs a model class, headers and rows, you can customize the items to be shown, and the headers and data for each row like this example
79
79
```php
80
80
<?php
81
81
@@ -87,10 +87,7 @@ use App\User;
87
87
88
88
class UsersTableView extends TableView
89
89
{
90
-
public function repository(): Builder
91
-
{
92
-
return User::query();
93
-
}
90
+
protected $model = User::class;
94
91
95
92
public function headers(): array
96
93
{
@@ -128,7 +125,7 @@ You could also use the `@livewire` blade directive.
128
125
129
126
At this point, you would be able to see a table with some data, the table view doesn't have any styled container or title as the image example, you can render the table view inside any container you want.
130
127
131
-
In the example above the view is using the User model created by default in every Laravel project, feel free to use any model you have, the method `row` is receiving a sinlge model object and you can use any property or public method you have difined inside your model.
128
+
In the example above the view is using the User model created by default in every Laravel project, feel free to use any model you want, the method `row` is receiving a sinlge model object and you can use any property or public method you have difined inside your model.
132
129
133
130
This is the basic usage of the table view, but you can customize it with more features.
134
131
@@ -183,7 +180,7 @@ Here's the plan for what's coming:
183
180
### From 2.2 to 2.3
184
181
- Clear your cached views `php artisan view:clear` since some of the internal components changed.
185
182
- Update components
186
-
- Update the renderIf() function in your action classes as follows:
183
+
- Update the renderIf() function in your action classes as follows:
187
184
```php
188
185
<?php
189
186
@@ -200,3 +197,4 @@ Here's the plan for what's coming:
200
197
}
201
198
}
202
199
```
200
+
-**(Optional)**, if your `repository` methods are returning the query object without any query applied like `User::query()`, you can define a `protected $model = User::class;` instead, this is the default behavior now, the `repository` method is still working so you don't need to change anything if you don't want to.
Copy file name to clipboardExpand all lines: doc/grid-view.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,17 +31,33 @@ With this artisan command a `ExampleGridView.php` file will be created inside `a
31
31
32
32
## Defining initial data
33
33
34
-
Return an `Eloquent` query with the initial data to be displayed on the grid view, it is important to return the query, not the data collection.
34
+
The GridView class needs a model class to get the initial data to be displayed on the table, you can define it in the `$model` property.
35
35
36
36
```php
37
37
use App\User;
38
38
39
+
protected $model = User::class;
40
+
```
41
+
42
+
If you need an specific query as initial data you can define a `repository` method returning an `Eloquent` query with the initial data to be displayed on the grid view, it is important to return the query, not the data collection.
43
+
44
+
```php
45
+
use App\User;
46
+
use Illuminate\Database\Eloquent\Builder;
47
+
48
+
/**
49
+
* Sets a initial query with the data to fill the table
50
+
*
51
+
* @return Builder Eloquent query
52
+
*/
39
53
public function repository(): Builder
40
54
{
41
55
return User::query();
42
56
}
43
57
```
44
58
59
+
If you define this method, the `$model` property is not needed anymore.
60
+
45
61
## Defining card data
46
62
47
63
You have to define a public function returning an array with the data that will be displayed on each card, this array has to include `photo`, `title`, `subtitle` and the `description`.
Copy file name to clipboardExpand all lines: doc/list-view.md
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,16 +31,31 @@ With this artisan command an `ExampleListView.php` file will be created inside t
31
31
32
32
## Defining initial data
33
33
34
-
You should return an `Eloquent` query with the initial data to be displayed on the list view, it is important to return the query, not the data collection.
34
+
The ListView class needs a model class to get the initial data to be displayed on the table, you can define it in the `$model` property.
35
35
36
36
```php
37
37
use App\User;
38
38
39
+
protected $model = User::class;
40
+
```
41
+
42
+
If you need an specific query as initial data you can define a `repository` method returning an `Eloquent` query with the initial data to be displayed on the list view, it is important to return the query, not the data collection.
43
+
44
+
```php
45
+
use App\User;
46
+
use Illuminate\Database\Eloquent\Builder;
47
+
48
+
/**
49
+
* Sets a initial query with the data to fill the table
50
+
*
51
+
* @return Builder Eloquent query
52
+
*/
39
53
public function repository(): Builder
40
54
{
41
55
return User::query();
42
56
}
43
57
```
58
+
If you define this method, the `$model` property is not needed anymore.
With this artisan command a `UsersTableView.php` file will be created inside `app/Http/Livewire` directory, with this class you can customize the behavior of the table view.
45
45
46
46
## Defining initial data
47
-
Return an `Eloquent` query with the initial data to be displayed on the table, it is important to return the query, not the data collection.
47
+
The TableView class needs a model class to get the initial data to be displayed on the table, you can define it in the `$model` property.
48
48
49
49
```php
50
50
use App\User;
51
51
52
+
protected $model = User::class;
53
+
```
54
+
55
+
If you need an specific query as initial data you can define a `repository` method returning an `Eloquent` query with the initial data to be displayed on the table, it is important to return the query, not the data collection.
56
+
57
+
```php
58
+
use App\User;
59
+
use Illuminate\Database\Eloquent\Builder;
60
+
61
+
/**
62
+
* Sets a initial query with the data to fill the table
63
+
*
64
+
* @return Builder Eloquent query
65
+
*/
52
66
public function repository(): Builder
53
67
{
54
68
return User::query();
55
69
}
56
70
```
57
71
72
+
If you define this method, the `$model` property is not needed anymore.
0 commit comments