Reputation: 41
I want to echo arry elemnts in view followings are my code (controller)
$next_d_dts= \DB::table('tb_billing_cycle')->select('next_due_bill_date')->where('customer_id',$row->customer_id)->get();
return view('invoice.view')->with('next_d_dts',$next_d_dts);
I can print it using print function, eg:
print_r($next_d_dts);
Output:
Array ( [0] => stdClass Object ( [next_due_bill_date] => 2019-03-28 ) [1] => stdClass Object ( [next_due_bill_date] => 2020-02-28 ) )
Upvotes: 3
Views: 13089
Reputation: 37
@foreach($next_d_dts as $value)
{{$value['next_due_bill_date']}}
@endforeach
Upvotes: 2
Reputation: 163768
You need to iterate over the collection of objects:
@foreach ($next_d_dts as $object)
{{ $object->name }}
@endforeach
If you just want to see its contents but not stop the script:
{{ var_dump($next_d_dts) }}
You've also asked how to iterate without Blade:
foreach ($next_d_dts as $object) {
echo $object->name;
}
Upvotes: 3
Reputation: 1326
You can convert it into array using toArray()
and iterate over it
$next_d_dts= \DB::table('tb_billing_cycle')->select('next_due_bill_date')->where('customer_id',$row->customer_id)->get()->toArray();
In view
@foreach($next_d_dts as $value)
{{ $value['column_name'] }}
@endforeach
Or
print_r($next_d_dts)
Upvotes: 1
Reputation: 4066
you should used foreach loop in laravel like this
@foreach ($next_d_dts as $value)
<p>Some text here{{ $value->id }}</p>
@endforeach
for more information read Laravel Manual blade template
Also you can used
dd($next_d_dts) //The dd function dumps the given variables and ends execution of the script
Upvotes: 1
Reputation: 7489
you need to use Blade Loops syntax invoice.view.blade.php
@foreach($next_d_dts as $next )
{{ $next }}
@endforeach
Upvotes: -1