Skip to content

Commit

Permalink
Fixed crud from issues
Browse files Browse the repository at this point in the history
  • Loading branch information
balajidharma committed Oct 14, 2024
1 parent e17ffaa commit 124357c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions resources/views/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
<thead>
<tr class="bg-base-200">
@foreach ($fields as $field)
@if ($field['list'] ?? true)
<th class="py-2 px-4 bg-base-50 font-bold uppercase text-sm text-left">
@if ($field['sortable'])
@include('crud::includes.sort-link', ['label' => $field['label'] ?? $field['attribute'], 'attribute' => $field['attribute']])
@else
{{ $field['label'] ?? $field['attribute'] }}
@endif
</th>
@endif
@endforeach
@canany(['adminUpdate', 'adminDelete'], $model)
<th class="py-2 px-4 bg-base-50 font-bold uppercase text-sm text-left">
Expand All @@ -40,9 +42,11 @@
@foreach($items as $item)
<tr>
@foreach ($fields as $field)
@isset($item->display_values[$field['attribute']])
<td class="p-4">
{!! $item->display_values[$field['attribute']] !!}
</td>
@endisset
@endforeach
@canany(['adminUpdate', 'adminDelete'], $item)
<td class="p-4">
Expand Down
7 changes: 5 additions & 2 deletions src/Column/LinkColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class LinkColumn extends Column

public function renderData($model, $index, $field)
{

$value = $model->{$field["attribute"]};
if (isset($field['list']['value'])) {
$value = $field['list']['value']($model);
}
$url = route($field['list']['route'], $this->getRouteParams($field['list']['route_params'], $model));

return '<a href="' . $url . '" '.render_form_attributes($field['list']['attr'] ?? []).'>' . $model->{$field["attribute"]} . '</a>';
return '<a href="' . $url . '" '.render_form_attributes($field['list']['attr'] ?? []).'>' . $value . '</a>';
}

protected function getRouteParams($routeParams, $model)
Expand Down
15 changes: 13 additions & 2 deletions src/CrudBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class CrudBuilder

public $showFieldErrors = false;

public $addtional = [];

public function __construct()
{
$this->crudHelper = new CrudHelper();
Expand All @@ -61,6 +63,11 @@ public function setIdentifier()
}
}

public function setAddtional($addtional)
{
$this->addtional = array_merge($this->addtional, $addtional);
}

public function list($dataProvider)
{
if (!($dataProvider instanceof Builder)) {
Expand Down Expand Up @@ -389,14 +396,18 @@ public function buildForm()
foreach ($this->fields as $field) {
if($field['filable'] && isset($field['label']))
{
$attribute = $field['attribute'];
$type = $field['type'];
$fieldOptions = isset($field['form_options']) ? $field['form_options']($this->dataProvider) : [];
if(!isset($fieldOptions['label']))
{
$fieldOptions['label'] = $field['label'];
}
$hideField = $fieldOptions['hide_field'] ?? false;
$hideField = $fieldOptions['hide'] ?? false;
$type = $fieldOptions['type'] ?? $type;
$attribute = $fieldOptions['attribute'] ?? $attribute;
if(!$hideField) {
$form->add($field['attribute'], $field['type'], $fieldOptions);
$form->add($attribute, $type, $fieldOptions);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/CrudHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getInputType($columnType)
'mediumtext' => 'textarea',
'numeric' => 'number',
'point' => 'text',
'password' => 'password',
'set' => 'checkbox',
'smallint' => 'number',
'string' => 'text',
Expand Down

0 comments on commit 124357c

Please sign in to comment.