Skip to content

Commit

Permalink
revert change that is apparently broken
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 13, 2017
1 parent e468fba commit eee83e8
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\View\Engines\EngineResolver;
Expand Down Expand Up @@ -149,44 +150,28 @@ public function make($view, $data = [], $mergeData = [])
*/
public function renderEach($view, $data, $iterator, $empty = 'raw|')
{
$result = '';
// If is actually data in the array, we will loop through the data and append
// an instance of the partial view to the final result HTML passing in the
// iterated value of this data array, allowing the views to access them.
if (count($data) > 0) {
return $this->renderEachView($view, $data, $iterator);
}
foreach ($data as $key => $value) {
$data = ['key' => $key, $iterator => $value];

$result .= $this->make($view, $data)->render();
}
}
// If there is no data in the array, we will render the contents of the empty
// view. Alternatively, the "empty view" could be a raw string that begins
// with "raw|" for convenience and to let this know that it is a string.
return $this->renderEmptyEach($empty);
}

/**
* Render the given view N number of times based on the data.
*
* @param string $view
* @param array $data
* @param string $iterator
* @return string
*/
protected function renderEachView($view, $data, $iterator)
{
return collect($data)->map(function ($value, $key) use ($view, $iterator) {
return $this->make($view, ['key' => $key, $iterator => $value])->render();
})->implode('');
}

/**
* Render an empty "each" view.
*
* @param string $empty
* @return string
*/
protected function renderEmptyEach($empty)
{
return Str::startsWith($empty, 'raw|')
? substr($empty, 4) : $this->make($empty)->render();
else {
if (Str::startsWith($empty, 'raw|')) {
$result = substr($empty, 4);
} else {
$result = $this->make($empty)->render();
}
}
return $result;
}

/**
Expand Down

0 comments on commit eee83e8

Please sign in to comment.