Skip to content

Commit 09467be

Browse files
committed
Add second parameter to view method for the name of the model variable available in the view.
1 parent d9c3a0e commit 09467be

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [0.1.6] - 2020-06-15
8+
9+
### Changed
10+
11+
- Add second parameter to view method for the name of the model variable available in the view.
12+
713
## [0.1.5] - 2020-05-26
814

915
### Changed
@@ -40,7 +46,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
4046

4147
- Initial release
4248

43-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.5...development
49+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.6...development
50+
[0.1.6]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.5...v0.1.6
4451
[0.1.5]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.4...v0.1.5
4552
[0.1.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.3...v0.1.4
4653
[0.1.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v0.1.2...v0.1.3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function customAttribute() : self;
137137
/**
138138
* This view will be used for the column, can still be used with sortable and searchable.
139139
*/
140-
public function view($view) : self;
140+
public function view($view, $viewModelName = 'model') : self;
141141
```
142142

143143
### Properties

resources/views/includes/_body.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class="{{ $this->setTableDataClass($column->attribute, Arr::get($model->toArray(
3737
@endforeach
3838
@endif
3939
@elseif ($column->isView())
40-
@include($column->view)
40+
@include($column->view, [$column->getViewModelName() => $model])
4141
@else
4242
@if ($column->isHtml())
4343
@if ($column->isCustomAttribute())

src/Views/Column.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class Column
6464
*/
6565
protected $view;
6666

67+
/**
68+
* The name of the model variable passed to the view
69+
*
70+
* @var string
71+
*/
72+
protected $viewModelName;
73+
6774
/**
6875
* Column constructor.
6976
*
@@ -215,16 +222,18 @@ public function isCustomAttribute(): bool
215222

216223
/**
217224
* @param $view
225+
* @param string $viewModelName
218226
*
219227
* @return $this
220228
*/
221-
public function view($view): self
229+
public function view($view, $viewModelName = 'model'): self
222230
{
223231
if ($this->hasComponents()) {
224232
return $this;
225233
}
226234

227235
$this->view = $view;
236+
$this->viewModelName = $viewModelName;
228237

229238
return $this;
230239
}
@@ -236,4 +245,11 @@ public function isView(): bool
236245
{
237246
return view()->exists($this->view);
238247
}
248+
249+
/**
250+
* @return string
251+
*/
252+
public function getViewModelName() {
253+
return $this->viewModelName;
254+
}
239255
}

0 commit comments

Comments
 (0)