@foreac laravel

PHP
  Route::get('/', 'PageController@index');
  Route::get('/welcome','PageController@Welcome');
  Route::get('/services', 'PageController@services');
  Route::get('/register', 'PageController@register');
  Route::get('/Create', 'PageController@Create');
  Route::get('/search', 'PageController@search');
  Route::get('/payment', 'PageController@Payment');



  Route::resource('posts', 'PostsController');
  Route::resource('search', 'SearchController');
  Route::resource('reviews', 'ReviewsController');
   /**
     * Compile the for-each statements into valid PHP.
     *
     * @param  string  $expression
     * @return string
     */
    protected function compileForeach($expression)
    {
        preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);

        $iteratee = trim($matches[1]);

        $iteration = trim($matches[2]);

        $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";

        $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';

        return "<?php {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} ?>";
    }


   /**
     * Compile the for-else statements into valid PHP.
     *
     * @param  string  $expression
     * @return string
     */
    protected function compileForelse($expression)
    {
        $empty = '$__empty_'.++$this->forElseCounter;

        preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);

        $iteratee = trim($matches[1]);

        $iteration = trim($matches[2]);

        $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";

        $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';

        return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>";
    }
@if(count($posts) > 1)
    @foreach($posts as $post)
        <h2><a href="/posts/{{$post->id}}">{{$post->title}}</a></h2>
    @endforeach
@else
    </p>no posts found</p>
@endif
    public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{
    return view('home');
}
@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

@forelse ($users as $user)
    <li>{{ $user->name }}</li>
@empty
    <p>No users</p>
@endforelse
public function index()
{
    $posts = Post::all();
    return view('Pages.welcome')->with('posts', $posts);
}
Route::get('/index','PageController@HomePage');
public function index()
{
    $posts = Post::all();
    return view('posts.index')->with('posts', $posts);
}
@foreach($posts as $post)

Source

Also in PHP: