Skip to content

Commit 2978e5e

Browse files
committed
feat: add new allow editing property
1 parent 675e2f3 commit 2978e5e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to `eloquent-datatable` will be documented in this file.
44

5+
## 1.1.0 - 2024-04-12
6+
- feat: add new allow editing property
7+
58
## 1.0.2 - 2024-04-07
69
- fix: the Route:datatable route
710

src/EloquentDatatable.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ trait EloquentDatatable
1616

1717
protected bool $allowCreation = true;
1818

19+
protected bool $allowEditing = true;
20+
1921
protected bool $createUsingDialog = false;
2022

2123
protected bool $allowSearching = true;
@@ -51,10 +53,11 @@ public function getResponse(Request $request): array
5153
'name' => $this->getDataTableName(),
5254
'name_singular' => Str::singular($this->getDataTableName()),
5355
'allow' => [
54-
'deletions' => $this->allowDeletion,
5556
'creation' => $this->allowCreation,
56-
'searching' => $this->allowSearching,
5757
'create_with_dialog' => $this->createUsingDialog,
58+
'editing' => $this->allowEditing,
59+
'deletions' => $this->allowDeletion,
60+
'searching' => $this->allowSearching,
5861
],
5962
'pagination_limit' => $this->getLimit($request),
6063
],
@@ -106,10 +109,8 @@ protected function getTableColumns(): array
106109
$columns = $builder->getColumnListing($table);
107110
$columnsWithType = collect($columns)->mapWithKeys(function ($item) use ($builder, $table) {
108111
$key = $builder->getColumnType($table, $item);
109-
110112
return [$item => $key];
111113
});
112-
113114
return $columnsWithType->toArray();
114115
}
115116

@@ -179,7 +180,9 @@ protected function itemStore(array $array): void
179180

180181
protected function itemUpdate(int $id, array $array): void
181182
{
182-
$this->builder->findOrFail($id)->update($array);
183+
if ($this->allowEditing) {
184+
$this->builder->findOrFail($id)->update($array);
185+
}
183186
}
184187

185188
/**

0 commit comments

Comments
 (0)