Skip to content

Commit 165bea3

Browse files
authored
Update README.md
1 parent 5b7ac4e commit 165bea3

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

README.md

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
*A powerful alternative to view composers. Asynchronous widgets, reloadable widgets, console generator, caching - everything you can think of.*
99

10-
### For Laravel 4, please use the [1.0 branch](https://github.com/Arrilot/laravel-widgets/tree/1.0)!
10+
### For Laravel 4, please use the [1.0 branch](https://github.com/arrilot/laravel-widgets/tree/1.0)!
1111

12-
> Note: This is the doc for the latest stable release. If you need documentation for your specific version you can find it by clicking on a corresponding tag here https://github.com/Arrilot/laravel-widgets/releases
12+
> Note: This is the doc for the latest stable release. If you need documentation for your specific version you can find it by clicking on a corresponding tag there https://github.com/arrilot/laravel-widgets/releases
1313
1414
## Installation
1515

@@ -27,7 +27,7 @@
2727
?>
2828
```
2929

30-
3) Add some facades here too. If you prefer custom blade directives instead of facades (see later) you can skip it.
30+
3) Add some facades here too. If you prefer custom blade directives to facades you can skip this step.
3131

3232
```php
3333
<?php
@@ -93,15 +93,15 @@ The last step is to call the widget.
9393
You've actually got several ways to do so.
9494

9595
```php
96-
{{ Widget::run('recentNews') }}
96+
@widget('recentNews')
9797
```
9898
or
9999
```php
100-
{{ Widget::recentNews() }}
100+
{{ Widget::run('recentNews') }}
101101
```
102102
or even
103103
```php
104-
@widget('recentNews')
104+
{{ Widget::recentNews() }}
105105
```
106106

107107
There is no real difference between them. The choice is up to you.
@@ -123,13 +123,11 @@ class RecentNews extends AbstractWidget {
123123
protected $config = [
124124
'count' => 5
125125
];
126-
127126
...
128127
}
129128

130129
...
131130
@widget('recentNews') // shows 5
132-
...
133131
@widget('recentNews', ['count' => 10]) // shows 10
134132
```
135133
`['count' => 10]` is a config array that can be accessed by $this->config.
@@ -152,7 +150,7 @@ class RecentNews extends AbstractWidget {
152150
@widget('recentNews', ['count' => 10]) // $this->config['foo'] is still 'bar'
153151
```
154152

155-
> Note2: You may want (but you probably don't) to create your own BaseWidget and inherit from it.
153+
> Note 2: You may want (but you probably don't) to create your own BaseWidget and inherit from it.
156154
That's fine. The only edge case is merging config defaults from a parent and a child.
157155
In this case do the following:
158156

@@ -178,41 +176,36 @@ You can also choose to pass additional parameters to `run()` method directly.
178176
```php
179177
@widget('recentNews', ['count' => 10], 'date', 'asc')
180178
...
181-
public function run($sort_by, $sort_order) { }
179+
public function run($sortBy, $sortOrder) { }
182180
...
183181
```
184182

185-
`run()` method is resolved via Service Container, so method injection is available here too.
183+
`run()` method is resolved via Service Container, so method injection is also available here.
186184

187185
## Namespaces
188186

189187
By default the package tries to find your widget in the ```App\Widgets``` namespace.
190188

191-
You can override this by publishing package config and setting `default_namespace` property.
192-
193-
Publish config command - ```php artisan vendor:publish --provider="Arrilot\Widgets\ServiceProvider"```
189+
You can override this by publishing package config (```php artisan vendor:publish --provider="Arrilot\Widgets\ServiceProvider"```) and setting `default_namespace` property.
194190

195-
Although using the default namespace is very convenient, in some situations you may wish to have more flexibility.
191+
Although using the default namespace is very convenient, in some cases you may wish to have more flexibility.
196192
For example, if you've got dozens of widgets it makes sense to group them in namespaced folders.
197193

198194
No problem, you have several ways to call those widgets:
199195

200196
1) Pass a full widget name from the `default_namespace` (basically `App\Widgets`) to the `run` method.
201197
```php
202198
@widget('News\RecentNews', $config)
203-
{{ Widget::run('News\RecentNews', $config) }}
204199
```
205200

206201
2) Use dot notation.
207202
```php
208203
@widget('news.recentNews', $config)
209-
{{ Widget::run('news.recentNews', $config) }}
210204
```
211205

212206
3) FQCN is also an option.
213207
```php
214208
@widget('\App\Http\Some\Namespace\Widget', $config)
215-
{{ Widget::run('\App\Http\Some\Namespace\Widget', $config) }}
216209
```
217210

218211
## Asynchronous widgets
@@ -224,7 +217,7 @@ All you need to do is to change facade or blade directive - `Widget::` => `Async
224217

225218
> Note: Widget params are encrypted and sent via ajax call. Expect them to be json_encoded and json_decoded afterwards.
226219
227-
> Note: Since version 3.1 you no longer need `jquery` to make ajax calls. However you can set `use_jquery_for_ajax_calls` to `true` in the config file if you need for some reason.
220+
> Note: Since version 3.1 you no longer need `jquery` to make ajax calls. However you can set `use_jquery_for_ajax_calls` to `true` in the config file if you want to.
228221
229222
By default nothing is shown until ajax call is finished.
230223

@@ -237,7 +230,7 @@ public function placeholder()
237230
}
238231
```
239232

240-
> Note: If you need to do smth with the routes package uses to load async widgets (e.g. you run app in a subfolder http://site.com/app/) you need to copy Arrilot\Widgets\ServiceProvider to your app, modify it according to your needs and register it in Laravel instead of the former one.
233+
> Side note: If you need to do smth with the routes package uses to load async widgets (e.g. you run app in a subfolder http://site.com/app/) you need to copy Arrilot\Widgets\ServiceProvider to your app, modify it according to your needs and register it in Laravel instead of the former one.
241234
242235
## Reloadable widgets
243236

@@ -260,12 +253,12 @@ class RecentNews extends AbstractWidget
260253
Both sync and async widgets can become reloadable.
261254

262255
You should use this feature with care, because it can easily spam your app with ajax calls if timeouts are too low.
263-
Consider using web sockets too but they are waaaay harder to set up on the other hand.
256+
Consider using web sockets too but they are way harder to set up.
264257

265258
## Container
266259

267260
Async and Reloadable widgets both require some DOM interaction so they wrap all widget output in a html container.
268-
This container is defined by AbstractWidget::container() method and can be customized therefore.
261+
This container is defined by `AbstractWidget::container()` method and can be customized too.
269262

270263
```php
271264
/**
@@ -283,7 +276,7 @@ This container is defined by AbstractWidget::container() method and can be custo
283276
}
284277
```
285278

286-
> Note: Nested async or reloadable widgets are not supported because of container id collision.
279+
> Note: Nested async or reloadable widgets are not supported.
287280
288281
## Caching
289282

@@ -310,17 +303,17 @@ Override ```cacheKey``` method if you need to adjust it.
310303
## Widget groups (extra)
311304

312305
In most cases Blade is a perfect tool for setting the position and order of widgets.
313-
However, in some cases you may find useful the approach with widget groups:
306+
However, sometimes you may find useful the following approach:
314307

315308
```php
316309
// add several widgets to the 'sidebar' group anywhere you want (even in controller)
317-
Widget::group('sidebar')->position(5)->addWidget(<the same arguments list as in run() method>);
318-
Widget::group('sidebar')->position(4)->addAsyncWidget(<the same arguments list as in run() method>);
310+
Widget::group('sidebar')->position(5)->addWidget('widgetName1', $config1);
311+
Widget::group('sidebar')->position(4)->addAsyncWidget('widgetName2', $config2);
319312

320313
// display them in a view in the correct order
321-
{{ Widget::group('sidebar')->display() }}
322-
//or
323314
@widgetGroup('sidebar')
315+
//or
316+
{{ Widget::group('sidebar')->display() }}
324317
```
325318

326319
`position()` can be omitted from the chain.

0 commit comments

Comments
 (0)