Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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:
<table class="table table-bordered table-hover" style="width:100%">
@foreach($audit->old_values as $attribute => $value)
<td><b>{{ $attribute }}</b></td>
<td>{{ $value }}</td>
@endforeach
</table>
So I apply the same to the new_values column and can't access the modifications:
<table class="table table-bordered table-hover" style="width:100%">
@foreach($audit->new_values as $attributee => $value)
<td><b>{{ $attributee }}</b></td>
<td>{{ $value }}</td>
@endforeach
</table>
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>
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
–
–
–
–
–
–
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)
<td><b>{{ $attribute2 }}</b></td>
<td>{{ $value2 }}</td>
@endforeach
</table>
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.