Search code examples
for-loopcontrollerlaravel-5.3

Unexpected for Loop error Laravel 5.3


I dont know why Im getting an error of

FatalErrorException in AdminController.php line 43: syntax error, unexpected 'for' (T_FOR)

on this line

$weekDays = array([]);

@for ($i = 0; $i < 7; $i++)
  $weekDays[] = strftime('%a', $timestamp);
   $timestamp = strtotime('+1 day', $timestamp);
@endfor

Can you guys help me? Lots of thanks!


Solution

  • That looks like it's in your controller and you are using the blade syntax, which is for templating. You need to use the standard php syntax in your controllers and other php classes:

    $weekDays = array([]);
    
    for ($i = 0; $i < 7; $i++){
      $weekDays[] = strftime('%a', $timestamp);
      $timestamp = strtotime('+1 day', $timestamp);
    }