$order = $user->orders()->save(factory(App\Order::class)->make()); in laravel 8 code example

Example 1: @foreac laravel

@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

Example 2: @foreac laravel

@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

Example 3: @foreac laravel

public function index()
{
    $posts = Post::all();
    return view('posts.index')->with('posts', $posts);
}

Tags:

Php Example