Skip to content

Commit cb365c6

Browse files
authored
Merge pull request yajra#54 from Namoshek/patch-2
Magic $model variable in blade templates.
2 parents 355d1ac + a0dbde1 commit cb365c6

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

add-column.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Add Column
22

3-
You can add a custom column on your response by using `addColumn` api.
3+
You can add a custom column to your response by using `addColumn` on the `DataTable` instance.
44

55
<a name="blade"></a>
66
## Add Column with Blade Syntax
@@ -12,11 +12,13 @@ Route::get('user-data', function() {
1212
$model = App\User::query();
1313

1414
return DataTables::eloquent($model)
15-
->addColumn('intro', 'Hi {{$name}}!')
15+
->addColumn('intro', 'Hi {{ $name }}!')
1616
->toJson();
1717
});
1818
```
1919

20+
> {tip} If you are building a DataTable for your `User` model which has the attributes `first_name` and `last_name`, you can directly access these properties in the blade template with `{{ $first_name }}` and `{{ $last_name }}`. You can also use `{{ $model->first_name }}` or `{{ $model->last_name }}` respectively, which is helpful if you need to call a method on the model like `{{ $model->getFullName() }}`.
21+
2022
<a name="closure"></a>
2123
## Add Column with Closure
2224

@@ -37,7 +39,7 @@ Route::get('user-data', function() {
3739
<a name="view"></a>
3840
## Add Column with View
3941

40-
> {tip} You can use view to render your added column by passing the view path as the second argument on `addColumn` api.
42+
You can also use a blade template to render a column by passing the view path as the second argument to `addColumn`.
4143

4244
```php
4345
use DataTables;
@@ -51,15 +53,17 @@ Route::get('user-data', function() {
5153
});
5254
```
5355

54-
Then create your view on `resources/views/users/datatables/intro.blade.php`.
56+
After creating the view in `resources/views/users/datatables/intro.blade.php`, you can then access all the properties of the DataTable row directly in your view:
5557
```php
5658
Hi {{ $name }}!
5759
```
5860

61+
> {tip} Similar to columns defined by an inline blade template, you can use `{{ $model->getFullName() }}` in views if you need access to the full model in order to call a method on it or similar.
62+
5963
<a name="order"></a>
6064
## Add Column with specific order
6165

62-
> {tip} Just pass the column order as the third argument of `addColumn` api.
66+
You can use a specific order for a column by passing the order as third argument to `addColumn`:
6367

6468
```php
6569
use DataTables;

0 commit comments

Comments
 (0)