slickness
102
22
Laravel

Undefined variable and other problems

Posted 1 year ago by slickness

I would like to display the created posts of the user with type 4 and 5 on his profile. The newest posts should be displayed first. But I always get the same error message:

Undefined variable: posts

public function getpost()
    {
        $postone = DB::table('posts')->get();

        return view('profiles.profile')
            ->with('posts', $postone);

    }
@foreach ($posts as $postone)
                                  @if (($post->type) === 4)
                                      <a class="img-hover" href="#">
                                      <img class="br-3 img-fluid" src="{{ Storage::url($post->image) }}" alt="" />
                                      </a>
                                  @else (($post->type) === 5)
                                      <a class="img-hover" href="#">
                                          <img class="br-3 img-fluid" src="{{ Storage::url($post->video) }}" alt="" />
                                      </a>
                                  @endif
                              @endforeach

Now I have three problems:

What am I doing wrong when displaying the data? How can I show the latest posts first? How can I just show the posts of the respective profile?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.