1

In my database i have a text field of

"6:00 AM Registration Opens; Day of Race registration (if available), check-in, packet pick up. 7:30 AM - First Wave Start. 10:00 AM - Awards Ceremony (time is approximate)."

What I am trying to do is have it break everywhere there is a .

@foreach($eventDetails as $info)
 <p>{{explode('.', $info->eventSchedule)}}</p>
@endforeach

The error I keep getting is

"Array to string conversion"
1
  • Because as soon as you made it an array, you try to print it as a string again. You need to explode it then loop through the resultant array to print. Might be easier to str_replace "." with ".<br>" Commented Jun 13, 2013 at 21:00

2 Answers 2

1

explode('.', $info->eventSchedule) returns an array() of strings. In blade templating engine (which Laravel uses), anything in double brackets {{ 'Hello world' }} is converted to and echo statement <?php echo 'Hello World'; ?>.

You cannot echo an array, so <?php echo explode('.', $info->eventSchedule); ?> fails. I'm not sure exactly your goal, but I would try this:

@foreach($eventDetails as $info)
    @foreach(explode('.', $info->eventSchedule) as $string)
        {{ $string }}
    @endforeach
@endforeach

This will now loop through the array created by explode(), and echo the String through blade's templating engine.

Sign up to request clarification or add additional context in comments.

Comments

0

Try str_replace() instead:

<p>{{str_replace('.','.<br>', $info->eventSchedule)}}</p>

2 Comments

This works, but I wouldn't consider it an answer that solves the problem. It avoids it, in my opinion. It could be a perfect solution depending on his scenario, though.
Thats what I thought, as there is no logic or processing of the array todo, it does what the OP asked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.