相关文章推荐
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

@Helioarch inspect with dd($audit-> new_values ​​()) 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>" ] – Rodrigo Ruiz Apr 8, 2020 at 23:27 where are you dd()ing ? i was asking for a var dump/dd in the blade because i was trying to make sure that no other code was modifying $audit->new_values before the loop.. – Helioarch Apr 8, 2020 at 23:56 @Helioarch I am having trouble executing {{var_dump ($ audit-> new_values)}}, it just throws the same error for me, I am testing it before it goes through the loop, any suggestions? – Rodrigo Ruiz Apr 9, 2020 at 1:00 oh i'm sorry i made the wrong suggestion.. can you instead do a @dd($audit->new_values) or @php(dd($audit->new_values)) right before the loop in your blade – Helioarch Apr 9, 2020 at 1:16 Thanks I have been dealing with this for a long time, you can solve it with the indicated. The problem was in a publish_at field in which I store the date. The date is important to me, how can I show only the date? In publish_at I get all this {"date":"2020-04-08 00:00:00.000000","timezone_type":3,"timezone":"America\/Argentina\/Buenos_Aires"} and just want the date. How can I show the date? – Rodrigo Ruiz Apr 9, 2020 at 2:26 @RodrigoRuiz You would have to show an example of the data in your publish_at field and your expected result. But please post it as another question to keep it clean. – Helioarch Apr 9, 2020 at 2:31

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>
                I followed his recommendation to change the names of the variables as I indicate, but I receive the same error, I ask him a question because if I use array_get it does not throw any error, but in this case it is not bringing me the values, look at my first image
– Rodrigo Ruiz
                Apr 8, 2020 at 23:52
        

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.

 
推荐文章