Home > Software engineering >  how to display array data in row view in laravel
how to display array data in row view in laravel

Time:03-07

array data enter image description here

my code in index.blade.php

 <tr>
    @php
        $filter_date = \Carbon\Carbon::parse(request()->query('filter_date'))->format('Y-m-d');
        $end_date = \Carbon\Carbon::parse(request()->query('end_date'))->format('Y-m-d');

     $dateRangePeriod = \Carbon\CarbonPeriod::create($filter_date, $end_date);
     $dateRange = [];
     
     foreach ($dateRangePeriod as $key => $date) {
           $dateRange[] = $date->format('d  F');
     }

    //return array :
    //dd($dateRange);

  @endphp
      
   <th colspan="4" > {{ $dateRange}}</th>

</tr>

i want to display array of data from date and to date in laravel view line. when i call data {{ $dateRange}} i get error: TypeError:htmlspecialchars(): Argument #1 ($string) must be of type string, array given. how to solve my problem, help me, thanks.

CodePudding user response:

Can you try changing your th tag <th colspan="4" > {{ $dateRange }}</th> to:

@foreach($dateRange as $date)
   <th >{{ $date }}</th>
@endforeach
  • Related