Laravel Print Array in Blade PHP

Printing array to blade

You should try this:

@foreach ($mail as $email)
<input type="text" name="to[]" value="{{$email}}">
@endforeach

Note: As you will have multiple values in $email you need to take array of input element as mentioned in above code (i.e name = "to[]")

Updated Answer

@foreach ($mail as $email)
@foreach ($mail as $emails)
<input type="text" name="to[]" value="{{$emails}}">
@endforeach
@endforeach

How to echo array elements in laravel

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;
}

Laravel Blade - Displaying array content

Blade has a feature where you can use or to mean "echo this if it exists, or this if it doesn't". So you can do

<td>{{ $array['leadData']['LeadID'] or '' }}</td>

And that basically results in what you want. Much cleaner, no? :)

Documentation: https://laravel.com/docs/5.2/blade#displaying-data - a few paragraphs down.

Printing array of object in .blade template

Use getContents() method to get response data and decode the json response using json_decode, Like this:

use GuzzleHttp\Client;

$client = new Client();
$response = $client->get('https://jsonplaceholder.typicode.com/posts');
$posts = json_decode($response->getBody()->getContents());
return view('home', compact('posts));

In your blade file you can render them as list items like so:

<ul>
@foreach($posts as $post)
<li> {{ $post->title }} </li>
@endforeach
</ul>

Extract only the values of array and print to blade LARAVEL

In the view you can loop over the array like this :

@foreach($mail as $email)
{{$email}}
@endforeach

To store them in the input you can do it like this :

{{ Form::text('emalis', implode(" ", $mail)) }}

Or

<input name="first_name" type="text" value={{implode(" ", $mail)}}>

Laravel - display the first image from an array in blade.php

Wow!!! i have found the solution.
The answer is to use json_decode() function.

<?php  $property_images = json_decode($files->images);?>
<img src="{{ asset('images/properties/'. $property_images[0]) }}" class="">


Related Topics



Leave a reply



Submit