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: README.md
+10-12Lines changed: 10 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,6 @@
11
11
12
12
Run ```composer require arrilot/laravel-widgets```
13
13
14
-
Laravel >=5.5 uses Package Auto-Discovery, so you don't need to manually add the ServiceProvider and Facades
15
-
16
14
## Usage
17
15
18
16
Let's consider that we want to make a list of recent news and reuse it in several views.
@@ -43,7 +41,7 @@ class RecentNews extends AbstractWidget
43
41
*
44
42
* @var array
45
43
*/
46
-
protected $config = [];
44
+
protected array $config = [];
47
45
48
46
/**
49
47
* Treat this method as a controller action.
@@ -92,7 +90,7 @@ This can be easily achieved by:
92
90
class RecentNews extends AbstractWidget
93
91
{
94
92
...
95
-
protected $config = [
93
+
protected array $config = [
96
94
'count' => 5
97
95
];
98
96
...
@@ -112,7 +110,7 @@ Config array is available in every widget method so you can use it to configure
112
110
class RecentNews extends AbstractWidget
113
111
{
114
112
...
115
-
protected $config = [
113
+
protected array $config = [
116
114
'count' => 5,
117
115
'foo' => 'bar'
118
116
];
@@ -129,7 +127,7 @@ In this case do the following:
129
127
130
128
1) Do not add `protected $config = [...]` line to a child.
131
129
132
-
2) Instead add defaults like this:
130
+
2) Instead, add defaults like this:
133
131
134
132
```php
135
133
public function __construct(array $config = [])
@@ -157,7 +155,7 @@ public function run($sortBy, $sortOrder) { }
157
155
158
156
## Namespaces
159
157
160
-
By default the package tries to find your widget in the ```App\Widgets``` namespace.
158
+
By default, the package tries to find your widget in the ```App\Widgets``` namespace.
161
159
162
160
You can override this by publishing package config (```php artisan vendor:publish --provider="Arrilot\Widgets\ServiceProvider"```) and setting `default_namespace` property.
163
161
@@ -183,7 +181,7 @@ No problem, there are several ways to call those widgets:
183
181
184
182
## Asynchronous widgets
185
183
186
-
In some situations it can be very beneficial to load widget content with AJAX.
184
+
Sometimes it can be very beneficial to load widget content with AJAX.
187
185
188
186
Fortunately, this can be achieved very easily!
189
187
All you need to do is to change facade or blade directive - `Widget::` => `AsyncWidget::`, `@widget` => `@asyncWidget`
@@ -195,12 +193,12 @@ For example, if you pass something like user_id through widget params and turn e
195
193
196
194
> Note: You can set `use_jquery_for_ajax_calls` to `true` in the config file to use it for ajax calls if you want to, but you need to manually add jquery to your page in this case.
197
195
198
-
By default nothing is shown until ajax call is finished.
196
+
By default, nothing is shown until ajax call is finished.
199
197
200
198
This can be customized by adding a `placeholder()` method to the widget class.
201
199
202
200
```php
203
-
public function placeholder()
201
+
public function placeholder(): string
204
202
{
205
203
return 'Loading...';
206
204
}
@@ -243,7 +241,7 @@ This container is defined by `AbstractWidget::container()` method and can be cus
243
241
*
244
242
* @return array
245
243
*/
246
-
public function container()
244
+
public function container(): array
247
245
{
248
246
return [
249
247
'element' => 'div',
@@ -292,7 +290,7 @@ class RecentNews extends AbstractWidget
0 commit comments