I am performing an audit, comparing between old_values and new_values fields. All the modifications made are stored in the columns (old_values and new_values), in TEXT format. I have a problem wanting to show the fields that have been modified and correspond to the new_values column of my audit table. This is how I loop through the old_values column without any problem:
<td>
<table class="table table-bordered table-hover" style="width:100%">
@foreach($audit->old_values as $attribute => $value)
<tr>
<td><b>{{ $attribute }}</b></td>
<td>{{ $value }}</td>
</tr>
@endforeach
</table>
</td>
So I apply the same to the new_values column and can't access the modifications:
<td>
<table class="table table-bordered table-hover" style="width:100%">
@foreach($audit->new_values as $attributee => $value)
<tr>
<td><b>{{ $attributee }}</b></td>
<td>{{ $value }}</td>
</tr>
@endforeach
</table>
</td>
This is the error:
htmlspecialchars() expects parameter 1 to be string, array given
So I tried the following: 1) inspect with dd ($ audit-> new_values) Outcome:
array:4 [▼
"category_id" => "2"
"title" => "Mi cuarto post edit"
"excerpt" => "Extracto de mi cuarto post edit"
"body" => "<p>Contenido de mi cuarto post edit</p>"
]
2) Then probe with array_get Outcome:
<td>{{ array_get($value, 'value.category_id'. default) }} </td>
This is my audit table: I want to show the data of the row that is highlighted in red (new_values):
Can someone help me solve this problem? How do I correctly cycle through my array?
UPDATED 1
Perform a new test by creating a new post, then edit the same post to compare the old_values and new_values fields. Inspecting I receive this error on line 62
Based on your comment and edits, it seems like you have a value that is in the form of an array so you could try to print it as string using {{ is_array($value2)? json_encode($value2): $value2 }}
{{ is_array($value2)? json_encode($value2): $value2 }}
For some reason, and to evict any naming problem while naming variables, I use other names to loop inside any collections or doing some stuff. Did you try too loop with:
<table class="table table-bordered table-hover" style="width:100%">
@foreach($audit->new_values as $attribute2 => $value2)
<tr>
<td><b>{{ $attribute2 }}</b></td>
<td>{{ $value2 }}</td>
</tr>
@endforeach
</table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.