@@ -44,13 +44,13 @@ Let's consider we want to make a list of recent news and reuse it in several vie
4444
4545First of all we can create a Widget class using the artisan command provided by the package.
4646``` bash
47- php artisan make:widget RecentNews --view
47+ php artisan make:widget RecentNews
4848```
4949This command generates two files:
5050
51511 ) ` resources/views/widgets/recent_news.blade.php ` is an empty view.
5252
53- Omit "--view " option if you do not need it .
53+ Add "--plain " option if you do not need a view .
5454
55552 ) ` app/Widgets/RecentNews ` is a widget class.
5656
@@ -63,15 +63,24 @@ use Arrilot\Widgets\AbstractWidget;
6363
6464class RecentNews extends AbstractWidget
6565{
66+ /**
67+ * The configuration array.
68+ *
69+ * @var array
70+ */
71+ protected $config = [];
72+
6673 /**
6774 * Treat this method as a controller action.
68- * Return a view or other content to display.
75+ * Return view() or other content to display.
6976 */
7077 public function run()
7178 {
7279 //
7380
74- return view("widgets.recent_news");
81+ return view("widgets.recent_news", [
82+ 'config' => $this->config,
83+ ]);
7584 }
7685}
7786```
@@ -113,13 +122,13 @@ class RecentNews extends AbstractWidget {
113122}
114123
115124...
116- @widget('recentNews')
125+ @widget('recentNews') // shows 5
117126...
118- @widget('recentNews', ['count' => 10])
127+ @widget('recentNews', ['count' => 10]) // shows 10
119128```
120- ` ['count' => 10] ` is a config array.
129+ ` ['count' => 10] ` is a config array that can be accessed by $this->config .
121130
122- Note: no config fields that are not specified when you call the widget are overwritten.
131+ Note: Config fields that are not specified when you call the widget aren't overwritten:
123132
124133``` php
125134class RecentNews extends AbstractWidget {
@@ -135,11 +144,11 @@ class RecentNews extends AbstractWidget {
135144@widget('recentNews', ['count' => 10]) // $this->config('foo') is still 'bar'
136145```
137146
138- Config array is available in all widget methods so you can use it to configure placeholder and container too.
147+ Config array is available in all widget methods so you can use it to configure placeholder and container too (see below)
139148
140149### Directly
141150
142- You can also choose to pass additional parameters to ` run() ` method directly if you like it .
151+ You can also choose to pass additional parameters to ` run() ` method directly.
143152
144153``` php
145154@widget('recentNews', ['count' => 10], 'date', 'asc')
@@ -161,7 +170,7 @@ For example, if you've got dozens of widgets it makes sense to group them in nam
161170
162171You have two ways to call those widgets:
163172
164- 1 ) You can pass the full widget name to the ` run ` method.
173+ 1 ) You can pass the full widget name from the ` default_namespace ` (basically ` App\Widgets ` ) to the ` run ` method.
165174``` php
166175@widget('News\RecentNews', $config)
167176{!! Widget::run('News\RecentNews', $config) !!}
@@ -230,8 +239,8 @@ Consider using web sockets too but they are waaaay harder to set up on the other
230239
231240## Container
232241
233- Async and Reloadable widgets both require some DOM interaction so they wrap all widget output in a Container .
234- This container is defined by AbstractWidget::container() method and can be customized
242+ Async and Reloadable widgets both require some DOM interaction so they wrap all widget output in a container .
243+ This container is defined by AbstractWidget::container() method and can be customized therefore.
235244
236245``` php
237246 /**
0 commit comments