简体   繁体   中英

Laravel Blade Foreach Output

I am trying to display the given array, but I cannot seem to get my head around the dimensions of it. I am exporting data from an excel sheet then to an array.

<?php

Excel::selectSheets('active_transport_sheet_1');
$reader->formatdates(true, 'd-m-Y');
$data = $reader->get(array('project_status', 'event_area', 'date_of_event', 'area_to_split', 
    'planned_split', 'actual_staff_on_split_requiring_transport', 'vehicle_type_required', 
    'project_number', 'event_name', 'driver_responsible_person',
    'hire_stauts', 'shift_start_time', 'departure_date', 'departure_time'))
    ->toArray();

$this->data = json_encode($data);
$this->data = json_decode($this->data, true);

Output

View

<div class="panel-body">
    @foreach ($sheet as $sheets)
        {{$sheets->date_of_event}}
    @endforeach
</div>

Error

"Trying to get property of non-object (View: C:\\xampp\\htdocs\\wallboards\\resources\\views\\boards\\viewexcel.blade.php)"

<div class="panel-body">
    @foreach ($sheet as $sheets)
        {{$sheets->date_of_event}}
    @endforeach
</div>

In the above code you are trying to access an object {{$sheets->date_of_event}} but its an array. So try $sheets['date_of_event']

So the full code is

<div class="panel-body">
     @foreach ($sheet as $sheets)
         {{$sheets['date_of_event']}}
     @endforeach
</div>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM